let Data = {};
exports.NewID = function (ID, dataHead, dataEnd) {
    try {
        if (Data.length >= 500) {
            for (let key in Data) {
                delete Data[key];
                break;
            }
        }
        Data[ID] = {
            "data1": [],
            "dataHead": dataHead,
            "dataEnd": dataEnd
        };
    } catch (error) {

    }
}
exports.InsertData = function (ID, Data_) {
    try {
        if (Data[ID] != undefined) {
            Data[ID].data1.splice(Data[ID].data1.length, 0, ...Array.from(new Uint8Array(Data_)));
        }
    } catch (error) {

    }
}
exports.SelectData = function (ID) {
    try {
        Data[ID].data1.splice(0, Data[ID].dataHead.length)
        Data[ID].data1.splice(Data[ID].data1.length - Data[ID].dataEnd.length, Data[ID].dataEnd.length)
        return Buffer.from(Data[ID].data1)
    } catch (error) {
        return Buffer.from([])
    }
}
exports.IFDataLength = function (ID) {
    try {
        let IfDataLength = true;
        for (let index = 0; index < Data[ID].dataEnd.length; index++) {
            if (Data[ID].data1[Data[ID].data1.length - index - 1] != Data[ID].dataEnd[Data[ID].dataEnd.length - index - 1]) {
                IfDataLength = false;
            }
        }
        return IfDataLength;
    } catch (error) {

    }
    return false;
}
exports.DeleteData = function (ID) {
    try {
        delete Data[ID];
    } catch (error) {

    }
}