@loaders.gl/netcdf 3.3.0-alpha.4 → 3.3.0-alpha.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/es5/index.js +4 -6
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/iobuffer/iobuffer.js +129 -105
- package/dist/es5/iobuffer/iobuffer.js.map +1 -1
- package/dist/es5/netcdf-loader.js +9 -27
- package/dist/es5/netcdf-loader.js.map +1 -1
- package/dist/es5/netcdfjs/netcdf-reader.js +33 -42
- package/dist/es5/netcdfjs/netcdf-reader.js.map +1 -1
- package/dist/es5/netcdfjs/netcdf-types.js.map +1 -1
- package/dist/es5/netcdfjs/read-data.js +4 -5
- package/dist/es5/netcdfjs/read-data.js.map +1 -1
- package/dist/es5/netcdfjs/read-header.js +12 -28
- package/dist/es5/netcdfjs/read-header.js.map +1 -1
- package/dist/es5/netcdfjs/read-type.js +4 -32
- package/dist/es5/netcdfjs/read-type.js.map +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/iobuffer/iobuffer.js +16 -74
- package/dist/esm/iobuffer/iobuffer.js.map +1 -1
- package/dist/esm/netcdf-loader.js +8 -7
- package/dist/esm/netcdf-loader.js.map +1 -1
- package/dist/esm/netcdfjs/netcdf-reader.js +2 -18
- package/dist/esm/netcdfjs/netcdf-reader.js.map +1 -1
- package/dist/esm/netcdfjs/netcdf-types.js.map +1 -1
- package/dist/esm/netcdfjs/read-data.js +6 -4
- package/dist/esm/netcdfjs/read-data.js.map +1 -1
- package/dist/esm/netcdfjs/read-header.js +13 -25
- package/dist/esm/netcdfjs/read-header.js.map +1 -1
- package/dist/esm/netcdfjs/read-type.js +4 -28
- package/dist/esm/netcdfjs/read-type.js.map +1 -1
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/netcdfjs/read-header.ts"],"names":["ZERO","NC_DIMENSION","NC_VARIABLE","NC_ATTRIBUTE","NC_UNLIMITED","readNetCDFHeader","buffer","version","recordDimensionLength","readUint32","dimList","readDimensionsList","attributes","readAttributesList","variableList","readVariablesList","recordId","header","recordDimension","length","id","name","recordName","recordStep","dimensions","variables","Error","dimensionSize","Array","dim","readName","size","gAttList","attributeSize","gAtt","type","value","padding","varList","variableSize","v","dimensionality","dimensionsIds","varSize","offset","record","nameLength","readChars","skip"],"mappings":";;;;;;;;AAEA;;AAGA,IAAMA,IAAI,GAAG,CAAb;AACA,IAAMC,YAAY,GAAG,EAArB;AACA,IAAMC,WAAW,GAAG,EAApB;AACA,IAAMC,YAAY,GAAG,EAArB;AAEA,IAAMC,YAAY,GAAG,CAArB;;AAQO,SAASC,gBAAT,CAA0BC,MAA1B,EAA4CC,OAA5C,EAA2E;AAGhF,MAAMC,qBAAqB,GAAGF,MAAM,CAACG,UAAP,EAA9B;AAGA,MAAMC,OAAO,GAAGC,kBAAkB,CAACL,MAAD,CAAlC;AAGA,MAAMM,UAAU,GAAGC,kBAAkB,CAACP,MAAD,CAArC;AAGA,MAAMQ,YAAY,GAAGC,iBAAiB,CAACT,MAAD,EAASI,OAAO,CAACM,QAAjB,EAA2BT,OAA3B,CAAtC;AAEA,MAAMU,MAAoB,GAAG;AAC3BV,IAAAA,OAAO,EAAPA,OAD2B;AAE3BW,IAAAA,eAAe,EAAE;AACfC,MAAAA,MAAM,EAAEX,qBADO;AAEfY,MAAAA,EAAE,EAAEV,OAAO,CAACM,QAFG;AAGfK,MAAAA,IAAI,EAAEX,OAAO,CAACY,UAHC;AAIfC,MAAAA,UAAU,EAAET,YAAY,CAACS;AAJV,KAFU;AAQ3BC,IAAAA,UAAU,EAAEd,OAAO,CAACc,UARO;AAS3BC,IAAAA,SAAS,EAAEX,YAAY,CAACW,SATG;AAU3Bb,IAAAA,UAAU,EAAVA;AAV2B,GAA7B;AAaA,SAAOK,MAAP;AACD;;AAOD,SAASN,kBAAT,CAA4BL,MAA5B,EAIE;AACA,MAAMI,OAAO,GAAGJ,MAAM,C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FVariable, NetCDFAttribute} from './netcdf-types';\nimport {readType, num2str} from './read-type';\n\n// Grammar constants\nconst ZERO = 0;\nconst NC_DIMENSION = 10;\nconst NC_VARIABLE = 11;\nconst NC_ATTRIBUTE = 12;\n\nconst NC_UNLIMITED = 0;\n\n/**\n * Read the header of the file\n * @param buffer - Buffer for the file data\n * @param version - Version of the file\n * @return - Header\n */\nexport function readNetCDFHeader(buffer: IOBuffer, version: number): NetCDFHeader {\n // Length of record dimension\n // sum of the varSize's of all the record variables.\n const recordDimensionLength = buffer.readUint32();\n\n // List of dimensions\n const dimList = readDimensionsList(buffer);\n\n // List of global attributes\n const attributes = readAttributesList(buffer);\n\n // List of variables\n const variableList = readVariablesList(buffer, dimList.recordId, version);\n\n const header: NetCDFHeader = {\n version,\n recordDimension: {\n length: recordDimensionLength,\n id: dimList.recordId, // id of the unlimited dimension\n name: dimList.recordName, // name of the unlimited dimension\n recordStep: variableList.recordStep\n },\n dimensions: dimList.dimensions,\n variables: variableList.variables,\n attributes\n };\n\n return header;\n}\n\n/**\n * Read list of dimensions\n * @ignore\n * @param {IOBuffer} buffer - Buffer for the file data\n */\nfunction readDimensionsList(buffer: IOBuffer): {\n recordId: number;\n recordName: string;\n dimensions: NetCDFDimension[];\n} {\n const dimList = buffer.readUint32();\n if (dimList === ZERO) {\n if (buffer.readUint32() !== ZERO) {\n throw new Error('NetCDF: wrong empty tag for list of dimensions');\n }\n // TODO - is this empty dimension list supported / recoverable?\n return {\n recordId: 0,\n recordName: '',\n dimensions: []\n };\n }\n\n if (dimList !== NC_DIMENSION) {\n throw new Error('NetCDF: wrong tag for list of dimensions');\n }\n\n // Length of dimensions\n const dimensionSize = buffer.readUint32();\n const dimensions = new Array(dimensionSize);\n let recordId;\n let recordName;\n for (let dim = 0; dim < dimensionSize; dim++) {\n // Read name\n const name = readName(buffer);\n\n // Read dimension size\n const size = buffer.readUint32();\n if (size === NC_UNLIMITED) {\n // in netcdf 3 one field can be of size unlimmited\n recordId = dim;\n recordName = name;\n }\n\n dimensions[dim] = {\n name,\n size\n };\n }\n\n return {\n dimensions,\n recordId,\n recordName\n };\n}\n\n/**\n * List of attributes\n * @ignore\n * @param buffer - Buffer for the file data\n * @return List of attributes with:\n */\nfunction readAttributesList(buffer: IOBuffer): NetCDFAttribute[] {\n const gAttList = buffer.readUint32();\n if (gAttList === ZERO) {\n if (buffer.readUint32() !== ZERO) {\n throw new Error('NetCDF: wrong empty tag for list of attributes');\n }\n return [];\n }\n\n if (gAttList !== NC_ATTRIBUTE) {\n throw new Error('NetCDF: wrong tag for list of attributes');\n }\n\n // Length of attributes\n const attributeSize = buffer.readUint32();\n const attributes = new Array(attributeSize);\n for (let gAtt = 0; gAtt < attributeSize; gAtt++) {\n // Read name\n const name = readName(buffer);\n\n // Read type\n const type = buffer.readUint32();\n if (type < 1 || type > 6) {\n throw new Error(`NetCDF: non valid type ${type}`);\n }\n\n // Read attribute\n const size = buffer.readUint32();\n const value = readType(buffer, type, size);\n\n // Apply padding\n padding(buffer);\n\n attributes[gAtt] = {\n name,\n type: num2str(type),\n value\n };\n }\n return attributes;\n}\n\n/**\n * List of variables\n * @param buffer - Buffer for the file data\n * @param recordId - Id of the unlimited dimension (also called record dimension)\n * This value may be undefined if there is no unlimited dimension\n * @param {number} version - Version of the file\n */\n// eslint-disable-next-line max-statements, complexity\nfunction readVariablesList(\n buffer: IOBuffer,\n recordId: number,\n version: number\n): {\n recordStep: number;\n variables: NetCDFVariable[];\n} {\n const varList = buffer.readUint32();\n let recordStep = 0;\n if (varList === ZERO) {\n if (buffer.readUint32() !== ZERO) {\n throw new Error('NetCDF: wrong empty tag for list of variables');\n }\n return {\n recordStep,\n variables: []\n };\n }\n\n if (varList !== NC_VARIABLE) {\n throw new Error('NetCDF: wrong tag for list of variables');\n }\n\n // Length of variables\n const variableSize = buffer.readUint32();\n const variables = new Array(variableSize);\n for (let v = 0; v < variableSize; v++) {\n // Read name\n const name = readName(buffer);\n\n // Read dimensionality of the variable\n const dimensionality = buffer.readUint32();\n\n // Index into the list of dimensions\n const dimensionsIds = new Array(dimensionality);\n for (let dim = 0; dim < dimensionality; dim++) {\n dimensionsIds[dim] = buffer.readUint32();\n }\n\n // Read variables size\n const attributes = readAttributesList(buffer);\n\n // Read type\n const type = buffer.readUint32();\n if (type < 1 && type > 6) {\n throw new Error(`NetCDF: non valid type ${type}`);\n }\n\n // Read variable size\n // The 32-bit varSize field is not large enough to contain the size of variables that require\n // more than 2^32 - 4 bytes, so 2^32 - 1 is used in the varSize field for such variables.\n const varSize = buffer.readUint32();\n\n // Read offset\n let offset = buffer.readUint32();\n if (version === 2) {\n if (offset > 0) {\n throw new Error('NetCDF: offsets larger than 4GB not supported');\n }\n offset = buffer.readUint32();\n }\n\n let record = false;\n // Count amount of record variables\n if (typeof recordId !== 'undefined' && dimensionsIds[0] === recordId) {\n recordStep += varSize;\n record = true;\n }\n variables[v] = {\n name,\n dimensions: dimensionsIds,\n attributes,\n type: num2str(type),\n size: varSize,\n offset,\n record\n };\n }\n\n return {\n variables,\n recordStep\n };\n}\n\n// HELPERS\n\n/**\n * Reads the name\n * @param buffer - Buffer for the file data\n * @return Name\n */\nexport function readName(buffer: IOBuffer): string {\n // Read name\n const nameLength = buffer.readUint32();\n const name = buffer.readChars(nameLength);\n\n // validate name\n // TODO\n\n // Apply padding\n padding(buffer);\n return name;\n}\n\n/**\n * Moves 1, 2, or 3 bytes to next 4-byte boundary\n */\nfunction padding(buffer: IOBuffer) {\n if (buffer.offset % 4 !== 0) {\n buffer.skip(4 - (buffer.offset % 4));\n }\n}\n"],"file":"read-header.js"}
|
|
1
|
+
{"version":3,"file":"read-header.js","names":["ZERO","NC_DIMENSION","NC_VARIABLE","NC_ATTRIBUTE","NC_UNLIMITED","readNetCDFHeader","buffer","version","recordDimensionLength","readUint32","dimList","readDimensionsList","attributes","readAttributesList","variableList","readVariablesList","recordId","header","recordDimension","length","id","name","recordName","recordStep","dimensions","variables","Error","dimensionSize","Array","dim","readName","size","gAttList","attributeSize","gAtt","type","value","readType","padding","num2str","varList","variableSize","v","dimensionality","dimensionsIds","varSize","offset","record","nameLength","readChars","skip"],"sources":["../../../src/netcdfjs/read-header.ts"],"sourcesContent":["import type {IOBuffer} from '../iobuffer/iobuffer';\nimport type {NetCDFHeader, NetCDFDimension, NetCDFVariable, NetCDFAttribute} from './netcdf-types';\nimport {readType, num2str} from './read-type';\n\n// Grammar constants\nconst ZERO = 0;\nconst NC_DIMENSION = 10;\nconst NC_VARIABLE = 11;\nconst NC_ATTRIBUTE = 12;\n\nconst NC_UNLIMITED = 0;\n\n/**\n * Read the header of the file\n * @param buffer - Buffer for the file data\n * @param version - Version of the file\n * @return - Header\n */\nexport function readNetCDFHeader(buffer: IOBuffer, version: number): NetCDFHeader {\n // Length of record dimension\n // sum of the varSize's of all the record variables.\n const recordDimensionLength = buffer.readUint32();\n\n // List of dimensions\n const dimList = readDimensionsList(buffer);\n\n // List of global attributes\n const attributes = readAttributesList(buffer);\n\n // List of variables\n const variableList = readVariablesList(buffer, dimList.recordId, version);\n\n const header: NetCDFHeader = {\n version,\n recordDimension: {\n length: recordDimensionLength,\n id: dimList.recordId, // id of the unlimited dimension\n name: dimList.recordName, // name of the unlimited dimension\n recordStep: variableList.recordStep\n },\n dimensions: dimList.dimensions,\n variables: variableList.variables,\n attributes\n };\n\n return header;\n}\n\n/**\n * Read list of dimensions\n * @ignore\n * @param {IOBuffer} buffer - Buffer for the file data\n */\nfunction readDimensionsList(buffer: IOBuffer): {\n recordId: number;\n recordName: string;\n dimensions: NetCDFDimension[];\n} {\n const dimList = buffer.readUint32();\n if (dimList === ZERO) {\n if (buffer.readUint32() !== ZERO) {\n throw new Error('NetCDF: wrong empty tag for list of dimensions');\n }\n // TODO - is this empty dimension list supported / recoverable?\n return {\n recordId: 0,\n recordName: '',\n dimensions: []\n };\n }\n\n if (dimList !== NC_DIMENSION) {\n throw new Error('NetCDF: wrong tag for list of dimensions');\n }\n\n // Length of dimensions\n const dimensionSize = buffer.readUint32();\n const dimensions = new Array(dimensionSize);\n let recordId;\n let recordName;\n for (let dim = 0; dim < dimensionSize; dim++) {\n // Read name\n const name = readName(buffer);\n\n // Read dimension size\n const size = buffer.readUint32();\n if (size === NC_UNLIMITED) {\n // in netcdf 3 one field can be of size unlimmited\n recordId = dim;\n recordName = name;\n }\n\n dimensions[dim] = {\n name,\n size\n };\n }\n\n return {\n dimensions,\n recordId,\n recordName\n };\n}\n\n/**\n * List of attributes\n * @ignore\n * @param buffer - Buffer for the file data\n * @return List of attributes with:\n */\nfunction readAttributesList(buffer: IOBuffer): NetCDFAttribute[] {\n const gAttList = buffer.readUint32();\n if (gAttList === ZERO) {\n if (buffer.readUint32() !== ZERO) {\n throw new Error('NetCDF: wrong empty tag for list of attributes');\n }\n return [];\n }\n\n if (gAttList !== NC_ATTRIBUTE) {\n throw new Error('NetCDF: wrong tag for list of attributes');\n }\n\n // Length of attributes\n const attributeSize = buffer.readUint32();\n const attributes = new Array(attributeSize);\n for (let gAtt = 0; gAtt < attributeSize; gAtt++) {\n // Read name\n const name = readName(buffer);\n\n // Read type\n const type = buffer.readUint32();\n if (type < 1 || type > 6) {\n throw new Error(`NetCDF: non valid type ${type}`);\n }\n\n // Read attribute\n const size = buffer.readUint32();\n const value = readType(buffer, type, size);\n\n // Apply padding\n padding(buffer);\n\n attributes[gAtt] = {\n name,\n type: num2str(type),\n value\n };\n }\n return attributes;\n}\n\n/**\n * List of variables\n * @param buffer - Buffer for the file data\n * @param recordId - Id of the unlimited dimension (also called record dimension)\n * This value may be undefined if there is no unlimited dimension\n * @param {number} version - Version of the file\n */\n// eslint-disable-next-line max-statements, complexity\nfunction readVariablesList(\n buffer: IOBuffer,\n recordId: number,\n version: number\n): {\n recordStep: number;\n variables: NetCDFVariable[];\n} {\n const varList = buffer.readUint32();\n let recordStep = 0;\n if (varList === ZERO) {\n if (buffer.readUint32() !== ZERO) {\n throw new Error('NetCDF: wrong empty tag for list of variables');\n }\n return {\n recordStep,\n variables: []\n };\n }\n\n if (varList !== NC_VARIABLE) {\n throw new Error('NetCDF: wrong tag for list of variables');\n }\n\n // Length of variables\n const variableSize = buffer.readUint32();\n const variables = new Array(variableSize);\n for (let v = 0; v < variableSize; v++) {\n // Read name\n const name = readName(buffer);\n\n // Read dimensionality of the variable\n const dimensionality = buffer.readUint32();\n\n // Index into the list of dimensions\n const dimensionsIds = new Array(dimensionality);\n for (let dim = 0; dim < dimensionality; dim++) {\n dimensionsIds[dim] = buffer.readUint32();\n }\n\n // Read variables size\n const attributes = readAttributesList(buffer);\n\n // Read type\n const type = buffer.readUint32();\n if (type < 1 && type > 6) {\n throw new Error(`NetCDF: non valid type ${type}`);\n }\n\n // Read variable size\n // The 32-bit varSize field is not large enough to contain the size of variables that require\n // more than 2^32 - 4 bytes, so 2^32 - 1 is used in the varSize field for such variables.\n const varSize = buffer.readUint32();\n\n // Read offset\n let offset = buffer.readUint32();\n if (version === 2) {\n if (offset > 0) {\n throw new Error('NetCDF: offsets larger than 4GB not supported');\n }\n offset = buffer.readUint32();\n }\n\n let record = false;\n // Count amount of record variables\n if (typeof recordId !== 'undefined' && dimensionsIds[0] === recordId) {\n recordStep += varSize;\n record = true;\n }\n variables[v] = {\n name,\n dimensions: dimensionsIds,\n attributes,\n type: num2str(type),\n size: varSize,\n offset,\n record\n };\n }\n\n return {\n variables,\n recordStep\n };\n}\n\n// HELPERS\n\n/**\n * Reads the name\n * @param buffer - Buffer for the file data\n * @return Name\n */\nexport function readName(buffer: IOBuffer): string {\n // Read name\n const nameLength = buffer.readUint32();\n const name = buffer.readChars(nameLength);\n\n // validate name\n // TODO\n\n // Apply padding\n padding(buffer);\n return name;\n}\n\n/**\n * Moves 1, 2, or 3 bytes to next 4-byte boundary\n */\nfunction padding(buffer: IOBuffer) {\n if (buffer.offset % 4 !== 0) {\n buffer.skip(4 - (buffer.offset % 4));\n }\n}\n"],"mappings":";;;;;;;AAEA;AAGA,IAAMA,IAAI,GAAG,CAAC;AACd,IAAMC,YAAY,GAA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,MAAM,EAANA;IACF,CAAC;EACH;EAEA,OAAO;IACLtB,SAAS,EAATA,SAAS;IACTF,UAAU,EAAVA;EACF,CAAC;AACH;;AASO,SAASO,QAAQ,CAACxB,MAAgB,EAAU;EAEjD,IAAM0C,UAAU,GAAG1C,MAAM,CAACG,UAAU,EAAE;EACtC,IAAMY,IAAI,GAAGf,MAAM,CAAC2C,SAAS,CAACD,UAAU,CAAC;;EAMzCV,OAAO,CAAChC,MAAM,CAAC;EACf,OAAOe,IAAI;AACb;;AAKA,SAASiB,OAAO,CAAChC,MAAgB,EAAE;EACjC,IAAIA,MAAM,CAACwC,MAAM,GAAG,CAAC,KAAK,CAAC,EAAE;IAC3BxC,MAAM,CAAC4C,IAAI,CAAC,CAAC,GAAI5C,MAAM,CAACwC,MAAM,GAAG,CAAE,CAAC;EACtC;AACF"}
|
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
7
|
-
exports.num2str = num2str;
|
|
6
|
+
exports.TYPES = void 0;
|
|
8
7
|
exports.num2bytes = num2bytes;
|
|
8
|
+
exports.num2str = num2str;
|
|
9
|
+
exports.readType = readType;
|
|
9
10
|
exports.str2num = str2num;
|
|
10
|
-
exports.TYPES = void 0;
|
|
11
11
|
var TYPES = {
|
|
12
12
|
BYTE: 1,
|
|
13
13
|
CHAR: 2,
|
|
@@ -16,28 +16,22 @@ var TYPES = {
|
|
|
16
16
|
FLOAT: 5,
|
|
17
17
|
DOUBLE: 6
|
|
18
18
|
};
|
|
19
|
-
exports.TYPES = TYPES;
|
|
20
19
|
|
|
20
|
+
exports.TYPES = TYPES;
|
|
21
21
|
function readType(buffer, type, size) {
|
|
22
22
|
switch (type) {
|
|
23
23
|
case TYPES.BYTE:
|
|
24
24
|
return buffer.readBytes(size);
|
|
25
|
-
|
|
26
25
|
case TYPES.CHAR:
|
|
27
26
|
return trimNull(buffer.readChars(size));
|
|
28
|
-
|
|
29
27
|
case TYPES.SHORT:
|
|
30
28
|
return readNumber(size, buffer.readInt16.bind(buffer));
|
|
31
|
-
|
|
32
29
|
case TYPES.INT:
|
|
33
30
|
return readNumber(size, buffer.readInt32.bind(buffer));
|
|
34
|
-
|
|
35
31
|
case TYPES.FLOAT:
|
|
36
32
|
return readNumber(size, buffer.readFloat32.bind(buffer));
|
|
37
|
-
|
|
38
33
|
case TYPES.DOUBLE:
|
|
39
34
|
return readNumber(size, buffer.readFloat64.bind(buffer));
|
|
40
|
-
|
|
41
35
|
default:
|
|
42
36
|
throw new Error("NetCDF: non valid type ".concat(type));
|
|
43
37
|
}
|
|
@@ -47,22 +41,16 @@ function num2str(type) {
|
|
|
47
41
|
switch (Number(type)) {
|
|
48
42
|
case TYPES.BYTE:
|
|
49
43
|
return 'byte';
|
|
50
|
-
|
|
51
44
|
case TYPES.CHAR:
|
|
52
45
|
return 'char';
|
|
53
|
-
|
|
54
46
|
case TYPES.SHORT:
|
|
55
47
|
return 'short';
|
|
56
|
-
|
|
57
48
|
case TYPES.INT:
|
|
58
49
|
return 'int';
|
|
59
|
-
|
|
60
50
|
case TYPES.FLOAT:
|
|
61
51
|
return 'float';
|
|
62
|
-
|
|
63
52
|
case TYPES.DOUBLE:
|
|
64
53
|
return 'double';
|
|
65
|
-
|
|
66
54
|
default:
|
|
67
55
|
return 'undefined';
|
|
68
56
|
}
|
|
@@ -72,22 +60,16 @@ function num2bytes(type) {
|
|
|
72
60
|
switch (Number(type)) {
|
|
73
61
|
case TYPES.BYTE:
|
|
74
62
|
return 1;
|
|
75
|
-
|
|
76
63
|
case TYPES.CHAR:
|
|
77
64
|
return 1;
|
|
78
|
-
|
|
79
65
|
case TYPES.SHORT:
|
|
80
66
|
return 2;
|
|
81
|
-
|
|
82
67
|
case TYPES.INT:
|
|
83
68
|
return 4;
|
|
84
|
-
|
|
85
69
|
case TYPES.FLOAT:
|
|
86
70
|
return 4;
|
|
87
|
-
|
|
88
71
|
case TYPES.DOUBLE:
|
|
89
72
|
return 8;
|
|
90
|
-
|
|
91
73
|
default:
|
|
92
74
|
return -1;
|
|
93
75
|
}
|
|
@@ -97,22 +79,16 @@ function str2num(type) {
|
|
|
97
79
|
switch (String(type)) {
|
|
98
80
|
case 'byte':
|
|
99
81
|
return TYPES.BYTE;
|
|
100
|
-
|
|
101
82
|
case 'char':
|
|
102
83
|
return TYPES.CHAR;
|
|
103
|
-
|
|
104
84
|
case 'short':
|
|
105
85
|
return TYPES.SHORT;
|
|
106
|
-
|
|
107
86
|
case 'int':
|
|
108
87
|
return TYPES.INT;
|
|
109
|
-
|
|
110
88
|
case 'float':
|
|
111
89
|
return TYPES.FLOAT;
|
|
112
|
-
|
|
113
90
|
case 'double':
|
|
114
91
|
return TYPES.DOUBLE;
|
|
115
|
-
|
|
116
92
|
default:
|
|
117
93
|
return -1;
|
|
118
94
|
}
|
|
@@ -121,14 +97,11 @@ function str2num(type) {
|
|
|
121
97
|
function readNumber(size, bufferReader) {
|
|
122
98
|
if (size !== 1) {
|
|
123
99
|
var numbers = new Array(size);
|
|
124
|
-
|
|
125
100
|
for (var i = 0; i < size; i++) {
|
|
126
101
|
numbers[i] = bufferReader();
|
|
127
102
|
}
|
|
128
|
-
|
|
129
103
|
return numbers;
|
|
130
104
|
}
|
|
131
|
-
|
|
132
105
|
return bufferReader();
|
|
133
106
|
}
|
|
134
107
|
|
|
@@ -136,7 +109,6 @@ function trimNull(value) {
|
|
|
136
109
|
if (value.charCodeAt(value.length - 1) === 0) {
|
|
137
110
|
return value.substring(0, value.length - 1);
|
|
138
111
|
}
|
|
139
|
-
|
|
140
112
|
return value;
|
|
141
113
|
}
|
|
142
114
|
//# sourceMappingURL=read-type.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"read-type.js","names":["TYPES","BYTE","CHAR","SHORT","INT","FLOAT","DOUBLE","readType","buffer","type","size","readBytes","trimNull","readChars","readNumber","readInt16","bind","readInt32","readFloat32","readFloat64","Error","num2str","Number","num2bytes","str2num","String","bufferReader","numbers","Array","i","value","charCodeAt","length","substring"],"sources":["../../../src/netcdfjs/read-type.ts"],"sourcesContent":["import {IOBuffer} from '../iobuffer/iobuffer';\n\nexport const TYPES = {\n BYTE: 1,\n CHAR: 2,\n SHORT: 3,\n INT: 4,\n FLOAT: 5,\n DOUBLE: 6\n};\n\n/**\n * Given a type and a size reads the next element\n * @param buffer - Buffer for the file data\n * @param type - Type of the data to read\n * @param size - Size of the element to read\n * @return\n */\nexport function readType(\n buffer: IOBuffer,\n type: number,\n size: number\n): string | number | number[] | Uint8Array {\n switch (type) {\n case TYPES.BYTE:\n return buffer.readBytes(size);\n case TYPES.CHAR:\n return trimNull(buffer.readChars(size));\n case TYPES.SHORT:\n return readNumber(size, buffer.readInt16.bind(buffer));\n case TYPES.INT:\n return readNumber(size, buffer.readInt32.bind(buffer));\n case TYPES.FLOAT:\n return readNumber(size, buffer.readFloat32.bind(buffer));\n case TYPES.DOUBLE:\n return readNumber(size, buffer.readFloat64.bind(buffer));\n /* istanbul ignore next */\n default:\n throw new Error(`NetCDF: non valid type ${type}`);\n }\n}\n\n/**\n * Parse a number into their respective type\n * @param type - integer that represents the type\n * @return parsed value of the type\n */\nexport function num2str(type: number): string {\n switch (Number(type)) {\n case TYPES.BYTE:\n return 'byte';\n case TYPES.CHAR:\n return 'char';\n case TYPES.SHORT:\n return 'short';\n case TYPES.INT:\n return 'int';\n case TYPES.FLOAT:\n return 'float';\n case TYPES.DOUBLE:\n return 'double';\n /* istanbul ignore next */\n default:\n return 'undefined';\n }\n}\n\n/**\n * Parse a number type identifier to his size in bytes\n * @param type - integer that represents the type\n * @return size of the type\n */\nexport function num2bytes(type: number): number {\n switch (Number(type)) {\n case TYPES.BYTE:\n return 1;\n case TYPES.CHAR:\n return 1;\n case TYPES.SHORT:\n return 2;\n case TYPES.INT:\n return 4;\n case TYPES.FLOAT:\n return 4;\n case TYPES.DOUBLE:\n return 8;\n /* istanbul ignore next */\n default:\n return -1;\n }\n}\n\n/**\n * Reverse search of num2str\n * @param type string that represents the type\n * @return parsed value of the type\n */\nexport function str2num(type: string): number {\n switch (String(type)) {\n case 'byte':\n return TYPES.BYTE;\n case 'char':\n return TYPES.CHAR;\n case 'short':\n return TYPES.SHORT;\n case 'int':\n return TYPES.INT;\n case 'float':\n return TYPES.FLOAT;\n case 'double':\n return TYPES.DOUBLE;\n /* istanbul ignore next */\n default:\n return -1;\n }\n}\n\n/**\n * Auxiliary function to read numeric data\n * @param size - Size of the element to read\n * @param bufferReader - Function to read next value\n * @return\n */\nfunction readNumber(size: number, bufferReader: () => number): number | number[] {\n if (size !== 1) {\n const numbers = new Array(size);\n for (let i = 0; i < size; i++) {\n numbers[i] = bufferReader();\n }\n return numbers;\n }\n return bufferReader();\n}\n\n/**\n * Removes null terminate value\n * @param value - String to trim\n * @return - Trimmed string\n */\nfunction trimNull(value: string): string {\n if (value.charCodeAt(value.length - 1) === 0) {\n return value.substring(0, value.length - 1);\n }\n return value;\n}\n"],"mappings":";;;;;;;;;;AAEO,IAAMA,KAAK,GAAG;EACnBC,IAAI,EAAE,CAAC;EACPC,IAAI,EAAE,CAAC;EACPC,KAAK,EAAE,CAAC;EACRC,GAAG,EAAE,CAAC;EACNC,KAAK,EAAE,CAAC;EACRC,MAAM,EAAE;AACV,CAAC;;AAAC;AASK,SAASC,QAAQ,CACtBC,MAAgB,EAChBC,IAAY,EACZC,IAAY,EAC6B;EACzC,QAAQD,IAAI;IACV,KAAKT,KAAK,CAACC,IAAI;MACb,OAAOO,MAAM,CAACG,SAAS,CAACD,IAAI,CAAC;IAC/B,KAAKV,KAAK,CAACE,IAAI;MACb,OAAOU,QAAQ,CAACJ,MAAM,CAACK,SAAS,CAACH,IAAI,CAAC,CAAC;IACzC,KAAKV,KAAK,CAACG,KAAK;MACd,OAAOW,UAAU,CAACJ,IAAI,EAAEF,MAAM,CAACO,SAAS,CAACC,IAAI,CAACR,MAAM,C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,CAAC,CAAC;EAAC;AAEhB;;AAOO,SAASkB,OAAO,CAACf,IAAY,EAAU;EAC5C,QAAQgB,MAAM,CAAChB,IAAI,CAAC;IAClB,KAAK,MAAM;MACT,OAAOT,KAAK,CAACC,IAAI;IACnB,KAAK,MAAM;MACT,OAAOD,KAAK,CAACE,IAAI;IACnB,KAAK,OAAO;MACV,OAAOF,KAAK,CAACG,KAAK;IACpB,KAAK,KAAK;MACR,OAAOH,KAAK,CAACI,GAAG;IAClB,KAAK,OAAO;MACV,OAAOJ,KAAK,CAACK,KAAK;IACpB,KAAK,QAAQ;MACX,OAAOL,KAAK,CAACM,MAAM;IAErB;MACE,OAAO,CAAC,CAAC;EAAC;AAEhB;;AAQA,SAASQ,UAAU,CAACJ,IAAY,EAAEgB,YAA0B,EAAqB;EAC/E,IAAIhB,IAAI,KAAK,CAAC,EAAE;IACd,IAAMiB,OAAO,GAAG,IAAIC,KAAK,CAAClB,IAAI,CAAC;IAC/B,KAAK,IAAImB,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGnB,IAAI,EAAEmB,CAAC,EAAE,EAAE;MAC7BF,OAAO,CAACE,CAAC,CAAC,GAAGH,YAAY,EAAE;IAC7B;IACA,OAAOC,OAAO;EAChB;EACA,OAAOD,YAAY,EAAE;AACvB;;AAOA,SAASd,QAAQ,CAACkB,KAAa,EAAU;EACvC,IAAIA,KAAK,CAACC,UAAU,CAACD,KAAK,CAACE,MAAM,GAAG,CAAC,CAAC,KAAK,CAAC,EAAE;IAC5C,OAAOF,KAAK,CAACG,SAAS,CAAC,CAAC,EAAEH,KAAK,CAACE,MAAM,GAAG,CAAC,CAAC;EAC7C;EACA,OAAOF,KAAK;AACd"}
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"index.js","names":["NetCDFReader","NetCDFLoader"],"sources":["../../src/index.ts"],"sourcesContent":["export {NetCDFReader} from './netcdfjs/netcdf-reader';\n\nexport {NetCDFLoader} from './netcdf-loader';\n"],"mappings":"AAAA,SAAQA,YAAY,QAAO,0BAA0B;AAErD,SAAQC,YAAY,QAAO,iBAAiB"}
|
|
@@ -1,58 +1,43 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
2
|
const DEFAULT_BYTE_LENGTH = 1024 * 8;
|
|
3
3
|
export class IOBuffer {
|
|
4
|
-
constructor(data = DEFAULT_BYTE_LENGTH, options = {}) {
|
|
5
|
-
_defineProperty(this, "buffer", void 0);
|
|
6
4
|
|
|
5
|
+
constructor() {
|
|
6
|
+
let data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : DEFAULT_BYTE_LENGTH;
|
|
7
|
+
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
8
|
+
_defineProperty(this, "buffer", void 0);
|
|
7
9
|
_defineProperty(this, "byteLength", void 0);
|
|
8
|
-
|
|
9
10
|
_defineProperty(this, "byteOffset", void 0);
|
|
10
|
-
|
|
11
11
|
_defineProperty(this, "length", void 0);
|
|
12
|
-
|
|
13
12
|
_defineProperty(this, "offset", void 0);
|
|
14
|
-
|
|
15
13
|
_defineProperty(this, "lastWrittenByte", void 0);
|
|
16
|
-
|
|
17
14
|
_defineProperty(this, "littleEndian", void 0);
|
|
18
|
-
|
|
19
15
|
_defineProperty(this, "_data", void 0);
|
|
20
|
-
|
|
21
16
|
_defineProperty(this, "_mark", void 0);
|
|
22
|
-
|
|
23
17
|
_defineProperty(this, "_marks", void 0);
|
|
24
|
-
|
|
25
18
|
_defineProperty(this, "textDecoder", new TextDecoder());
|
|
26
|
-
|
|
27
19
|
_defineProperty(this, "textEncoder", new TextEncoder());
|
|
28
|
-
|
|
29
20
|
let dataIsGiven = false;
|
|
30
|
-
|
|
31
21
|
if (typeof data === 'number') {
|
|
32
22
|
data = new ArrayBuffer(data);
|
|
33
23
|
} else {
|
|
34
24
|
dataIsGiven = true;
|
|
35
25
|
this.lastWrittenByte = data.byteLength;
|
|
36
26
|
}
|
|
37
|
-
|
|
38
27
|
const offset = options.offset ? options.offset >>> 0 : 0;
|
|
39
28
|
const byteLength = data.byteLength - offset;
|
|
40
29
|
let dvOffset = offset;
|
|
41
|
-
|
|
42
30
|
if (ArrayBuffer.isView(data) || data instanceof IOBuffer) {
|
|
43
31
|
if (data.byteLength !== data.buffer.byteLength) {
|
|
44
32
|
dvOffset = data.byteOffset + offset;
|
|
45
33
|
}
|
|
46
|
-
|
|
47
34
|
data = data.buffer;
|
|
48
35
|
}
|
|
49
|
-
|
|
50
36
|
if (dataIsGiven) {
|
|
51
37
|
this.lastWrittenByte = byteLength;
|
|
52
38
|
} else {
|
|
53
39
|
this.lastWrittenByte = 0;
|
|
54
40
|
}
|
|
55
|
-
|
|
56
41
|
this.buffer = data;
|
|
57
42
|
this.length = byteLength;
|
|
58
43
|
this.byteLength = byteLength;
|
|
@@ -64,7 +49,8 @@ export class IOBuffer {
|
|
|
64
49
|
this._marks = [];
|
|
65
50
|
}
|
|
66
51
|
|
|
67
|
-
available(
|
|
52
|
+
available() {
|
|
53
|
+
let byteLength = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
|
|
68
54
|
return this.offset + byteLength <= this.length;
|
|
69
55
|
}
|
|
70
56
|
|
|
@@ -86,7 +72,8 @@ export class IOBuffer {
|
|
|
86
72
|
return this;
|
|
87
73
|
}
|
|
88
74
|
|
|
89
|
-
skip(
|
|
75
|
+
skip() {
|
|
76
|
+
let n = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
|
|
90
77
|
this.offset += n;
|
|
91
78
|
return this;
|
|
92
79
|
}
|
|
@@ -108,17 +95,14 @@ export class IOBuffer {
|
|
|
108
95
|
|
|
109
96
|
pushMark() {
|
|
110
97
|
this._marks.push(this.offset);
|
|
111
|
-
|
|
112
98
|
return this;
|
|
113
99
|
}
|
|
114
100
|
|
|
115
101
|
popMark() {
|
|
116
102
|
const offset = this._marks.pop();
|
|
117
|
-
|
|
118
103
|
if (offset === undefined) {
|
|
119
104
|
throw new Error('Mark stack empty');
|
|
120
105
|
}
|
|
121
|
-
|
|
122
106
|
this.seek(offset);
|
|
123
107
|
return this;
|
|
124
108
|
}
|
|
@@ -128,7 +112,8 @@ export class IOBuffer {
|
|
|
128
112
|
return this;
|
|
129
113
|
}
|
|
130
114
|
|
|
131
|
-
ensureAvailable(
|
|
115
|
+
ensureAvailable() {
|
|
116
|
+
let byteLength = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
|
|
132
117
|
if (!this.available(byteLength)) {
|
|
133
118
|
const lengthNeeded = this.offset + byteLength;
|
|
134
119
|
const newLength = lengthNeeded * 2;
|
|
@@ -138,7 +123,6 @@ export class IOBuffer {
|
|
|
138
123
|
this.length = this.byteLength = newLength;
|
|
139
124
|
this._data = new DataView(this.buffer);
|
|
140
125
|
}
|
|
141
|
-
|
|
142
126
|
return this;
|
|
143
127
|
}
|
|
144
128
|
|
|
@@ -158,54 +142,47 @@ export class IOBuffer {
|
|
|
158
142
|
return this.readUint8();
|
|
159
143
|
}
|
|
160
144
|
|
|
161
|
-
readBytes(
|
|
145
|
+
readBytes() {
|
|
146
|
+
let n = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
|
|
162
147
|
const bytes = new Uint8Array(n);
|
|
163
|
-
|
|
164
148
|
for (let i = 0; i < n; i++) {
|
|
165
149
|
bytes[i] = this.readByte();
|
|
166
150
|
}
|
|
167
|
-
|
|
168
151
|
return bytes;
|
|
169
152
|
}
|
|
170
153
|
|
|
171
154
|
readInt16() {
|
|
172
155
|
const value = this._data.getInt16(this.offset, this.littleEndian);
|
|
173
|
-
|
|
174
156
|
this.offset += 2;
|
|
175
157
|
return value;
|
|
176
158
|
}
|
|
177
159
|
|
|
178
160
|
readUint16() {
|
|
179
161
|
const value = this._data.getUint16(this.offset, this.littleEndian);
|
|
180
|
-
|
|
181
162
|
this.offset += 2;
|
|
182
163
|
return value;
|
|
183
164
|
}
|
|
184
165
|
|
|
185
166
|
readInt32() {
|
|
186
167
|
const value = this._data.getInt32(this.offset, this.littleEndian);
|
|
187
|
-
|
|
188
168
|
this.offset += 4;
|
|
189
169
|
return value;
|
|
190
170
|
}
|
|
191
171
|
|
|
192
172
|
readUint32() {
|
|
193
173
|
const value = this._data.getUint32(this.offset, this.littleEndian);
|
|
194
|
-
|
|
195
174
|
this.offset += 4;
|
|
196
175
|
return value;
|
|
197
176
|
}
|
|
198
177
|
|
|
199
178
|
readFloat32() {
|
|
200
179
|
const value = this._data.getFloat32(this.offset, this.littleEndian);
|
|
201
|
-
|
|
202
180
|
this.offset += 4;
|
|
203
181
|
return value;
|
|
204
182
|
}
|
|
205
183
|
|
|
206
184
|
readFloat64() {
|
|
207
185
|
const value = this._data.getFloat64(this.offset, this.littleEndian);
|
|
208
|
-
|
|
209
186
|
this.offset += 8;
|
|
210
187
|
return value;
|
|
211
188
|
}
|
|
@@ -214,17 +191,17 @@ export class IOBuffer {
|
|
|
214
191
|
return String.fromCharCode(this.readInt8());
|
|
215
192
|
}
|
|
216
193
|
|
|
217
|
-
readChars(
|
|
194
|
+
readChars() {
|
|
195
|
+
let n = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
|
|
218
196
|
let result = '';
|
|
219
|
-
|
|
220
197
|
for (let i = 0; i < n; i++) {
|
|
221
198
|
result += this.readChar();
|
|
222
199
|
}
|
|
223
|
-
|
|
224
200
|
return result;
|
|
225
201
|
}
|
|
226
202
|
|
|
227
|
-
readUtf8(
|
|
203
|
+
readUtf8() {
|
|
204
|
+
let n = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
|
|
228
205
|
return this.textDecoder.decode(this.readBytes(n));
|
|
229
206
|
}
|
|
230
207
|
|
|
@@ -235,21 +212,15 @@ export class IOBuffer {
|
|
|
235
212
|
|
|
236
213
|
writeInt8(value) {
|
|
237
214
|
this.ensureAvailable(1);
|
|
238
|
-
|
|
239
215
|
this._data.setInt8(this.offset++, value);
|
|
240
|
-
|
|
241
216
|
this._updateLastWrittenByte();
|
|
242
|
-
|
|
243
217
|
return this;
|
|
244
218
|
}
|
|
245
219
|
|
|
246
220
|
writeUint8(value) {
|
|
247
221
|
this.ensureAvailable(1);
|
|
248
|
-
|
|
249
222
|
this._data.setUint8(this.offset++, value);
|
|
250
|
-
|
|
251
223
|
this._updateLastWrittenByte();
|
|
252
|
-
|
|
253
224
|
return this;
|
|
254
225
|
}
|
|
255
226
|
|
|
@@ -259,85 +230,58 @@ export class IOBuffer {
|
|
|
259
230
|
|
|
260
231
|
writeBytes(bytes) {
|
|
261
232
|
this.ensureAvailable(bytes.length);
|
|
262
|
-
|
|
263
233
|
for (let i = 0; i < bytes.length; i++) {
|
|
264
234
|
this._data.setUint8(this.offset++, bytes[i]);
|
|
265
235
|
}
|
|
266
|
-
|
|
267
236
|
this._updateLastWrittenByte();
|
|
268
|
-
|
|
269
237
|
return this;
|
|
270
238
|
}
|
|
271
239
|
|
|
272
240
|
writeInt16(value) {
|
|
273
241
|
this.ensureAvailable(2);
|
|
274
|
-
|
|
275
242
|
this._data.setInt16(this.offset, value, this.littleEndian);
|
|
276
|
-
|
|
277
243
|
this.offset += 2;
|
|
278
|
-
|
|
279
244
|
this._updateLastWrittenByte();
|
|
280
|
-
|
|
281
245
|
return this;
|
|
282
246
|
}
|
|
283
247
|
|
|
284
248
|
writeUint16(value) {
|
|
285
249
|
this.ensureAvailable(2);
|
|
286
|
-
|
|
287
250
|
this._data.setUint16(this.offset, value, this.littleEndian);
|
|
288
|
-
|
|
289
251
|
this.offset += 2;
|
|
290
|
-
|
|
291
252
|
this._updateLastWrittenByte();
|
|
292
|
-
|
|
293
253
|
return this;
|
|
294
254
|
}
|
|
295
255
|
|
|
296
256
|
writeInt32(value) {
|
|
297
257
|
this.ensureAvailable(4);
|
|
298
|
-
|
|
299
258
|
this._data.setInt32(this.offset, value, this.littleEndian);
|
|
300
|
-
|
|
301
259
|
this.offset += 4;
|
|
302
|
-
|
|
303
260
|
this._updateLastWrittenByte();
|
|
304
|
-
|
|
305
261
|
return this;
|
|
306
262
|
}
|
|
307
263
|
|
|
308
264
|
writeUint32(value) {
|
|
309
265
|
this.ensureAvailable(4);
|
|
310
|
-
|
|
311
266
|
this._data.setUint32(this.offset, value, this.littleEndian);
|
|
312
|
-
|
|
313
267
|
this.offset += 4;
|
|
314
|
-
|
|
315
268
|
this._updateLastWrittenByte();
|
|
316
|
-
|
|
317
269
|
return this;
|
|
318
270
|
}
|
|
319
271
|
|
|
320
272
|
writeFloat32(value) {
|
|
321
273
|
this.ensureAvailable(4);
|
|
322
|
-
|
|
323
274
|
this._data.setFloat32(this.offset, value, this.littleEndian);
|
|
324
|
-
|
|
325
275
|
this.offset += 4;
|
|
326
|
-
|
|
327
276
|
this._updateLastWrittenByte();
|
|
328
|
-
|
|
329
277
|
return this;
|
|
330
278
|
}
|
|
331
279
|
|
|
332
280
|
writeFloat64(value) {
|
|
333
281
|
this.ensureAvailable(8);
|
|
334
|
-
|
|
335
282
|
this._data.setFloat64(this.offset, value, this.littleEndian);
|
|
336
|
-
|
|
337
283
|
this.offset += 8;
|
|
338
|
-
|
|
339
284
|
this._updateLastWrittenByte();
|
|
340
|
-
|
|
341
285
|
return this;
|
|
342
286
|
}
|
|
343
287
|
|
|
@@ -349,7 +293,6 @@ export class IOBuffer {
|
|
|
349
293
|
for (let i = 0; i < str.length; i++) {
|
|
350
294
|
this.writeUint8(str.charCodeAt(i));
|
|
351
295
|
}
|
|
352
|
-
|
|
353
296
|
return this;
|
|
354
297
|
}
|
|
355
298
|
|
|
@@ -367,6 +310,5 @@ export class IOBuffer {
|
|
|
367
310
|
this.lastWrittenByte = this.offset;
|
|
368
311
|
}
|
|
369
312
|
}
|
|
370
|
-
|
|
371
313
|
}
|
|
372
314
|
//# sourceMappingURL=iobuffer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/iobuffer/iobuffer.ts"],"names":["DEFAULT_BYTE_LENGTH","IOBuffer","constructor","data","options","TextDecoder","TextEncoder","dataIsGiven","ArrayBuffer","lastWrittenByte","byteLength","offset","dvOffset","isView","buffer","byteOffset","length","littleEndian","_data","DataView","_mark","_marks","available","isLittleEndian","setLittleEndian","isBigEndian","setBigEndian","skip","n","seek","mark","reset","pushMark","push","popMark","pop","undefined","Error","rewind","ensureAvailable","lengthNeeded","newLength","newArray","Uint8Array","set","readBoolean","readUint8","readInt8","getInt8","getUint8","readByte","readBytes","bytes","i","readInt16","value","getInt16","readUint16","getUint16","readInt32","getInt32","readUint32","getUint32","readFloat32","getFloat32","readFloat64","getFloat64","readChar","String","fromCharCode","readChars","result","readUtf8","textDecoder","decode","writeBoolean","writeUint8","writeInt8","setInt8","_updateLastWrittenByte","setUint8","writeByte","writeBytes","writeInt16","setInt16","writeUint16","setUint16","writeInt32","setInt32","writeUint32","setUint32","writeFloat32","setFloat32","writeFloat64","setFloat64","writeChar","str","charCodeAt","writeChars","writeUtf8","textEncoder","encode","toArray"],"mappings":";AAAA,MAAMA,mBAAmB,GAAG,OAAO,CAAnC;AAWA,OAAO,MAAMC,QAAN,CAAe;AA4CbC,EAAAA,WAAW,CAACC,IAAe,GAAGH,mBAAnB,EAAwCI,OAAwB,GAAG,EAAnE,EAAuE;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA,yCAXnE,IAAIC,WAAJ,EAWmE;;AAAA,yCAVnE,IAAIC,WAAJ,EAUmE;;AACvF,QAAIC,WAAW,GAAG,KAAlB;;AACA,QAAI,OAAOJ,IAAP,KAAgB,QAApB,EAA8B;AAC5BA,MAAAA,IAAI,GAAG,IAAIK,WAAJ,CAAgBL,IAAhB,CAAP;AACD,KAFD,MAEO;AACLI,MAAAA,WAAW,GAAG,IAAd;AACA,WAAKE,eAAL,GAAuBN,IAAI,CAACO,UAA5B;AACD;;AAED,UAAMC,MAAM,GAAGP,OAAO,CAACO,MAAR,GAAiBP,O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IAAe,CAAf;;AACA,SAAKoE,sBAAL;;AACA,WAAO,IAAP;AACD;;AAMMgB,EAAAA,SAAS,CAACC,GAAD,EAAoB;AAClC,WAAO,KAAKpB,UAAL,CAAgBoB,GAAG,CAACC,UAAJ,CAAe,CAAf,CAAhB,CAAP;AACD;;AAMMC,EAAAA,UAAU,CAACF,GAAD,EAAoB;AACnC,SAAK,IAAI3C,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAG2C,GAAG,CAAChF,MAAxB,EAAgCqC,CAAC,EAAjC,EAAqC;AACnC,WAAKuB,UAAL,CAAgBoB,GAAG,CAACC,UAAJ,CAAe5C,CAAf,CAAhB;AACD;;AACD,WAAO,IAAP;AACD;;AAMM8C,EAAAA,SAAS,CAACH,GAAD,EAAoB;AAClC,UAAM5C,KAAK,GAAG,KAAKgD,WAAL,CAAiBC,MAAjB,CAAwBL,GAAxB,CAAd;AACA,WAAO,KAAKd,UAAL,CAAgB9B,KAAhB,CAAP;AACD;;AAOMkD,EAAAA,OAAO,GAAe;AAC3B,WAAO,IAAI3D,UAAJ,CAAe,KAAK7B,MAApB,EAA4B,KAAKC,UAAjC,EAA6C,KAAKN,eAAlD,CAAP;AACD;;AAMOsE,EAAAA,sBAAsB,GAAS;AACrC,QAAI,KAAKpE,MAAL,GAAc,KAAKF,eAAvB,EAAwC;AACtC,WAAKA,eAAL,GAAuB,KAAKE,MAA5B;AACD;AACF;;AA/emB","sourcesContent":["const DEFAULT_BYTE_LENGTH = 1024 * 8;\n\ntype InputData = number | ArrayBufferLike | ArrayBufferView | IOBuffer | Buffer;\n\ninterface IOBufferOptions {\n /**\n * Ignore the first n bytes of the ArrayBuffer.\n */\n offset?: number;\n}\n\nexport class IOBuffer {\n /**\n * Reference to the internal ArrayBuffer object.\n */\n public buffer: ArrayBufferLike;\n\n /**\n * Byte length of the internal ArrayBuffer.\n */\n public byteLength: number;\n\n /**\n * Byte offset of the internal ArrayBuffer.\n */\n public byteOffset: number;\n\n /**\n * Byte length of the internal ArrayBuffer.\n */\n public length: number;\n\n /**\n * The current offset of the buffer's pointer.\n */\n public offset: number;\n\n private lastWrittenByte: number;\n private littleEndian: boolean;\n\n private _data: DataView;\n private _mark: number;\n private _marks: number[];\n\n private textDecoder = new TextDecoder();\n private textEncoder = new TextEncoder();\n\n /**\n * @param data - The data to construct the IOBuffer with.\n * If data is a number, it will be the new buffer's length<br>\n * If data is `undefined`, the buffer will be initialized with a default length of 8Kb<br>\n * If data is an ArrayBuffer, SharedArrayBuffer, an ArrayBufferView (Typed Array), an IOBuffer instance,\n * or a Node.js Buffer, a view will be created over the underlying ArrayBuffer.\n * @param options\n */\n public constructor(data: InputData = DEFAULT_BYTE_LENGTH, options: IOBufferOptions = {}) {\n let dataIsGiven = false;\n if (typeof data === 'number') {\n data = new ArrayBuffer(data);\n } else {\n dataIsGiven = true;\n this.lastWrittenByte = data.byteLength;\n }\n\n const offset = options.offset ? options.offset >>> 0 : 0;\n const byteLength = data.byteLength - offset;\n let dvOffset = offset;\n if (ArrayBuffer.isView(data) || data instanceof IOBuffer) {\n if (data.byteLength !== data.buffer.byteLength) {\n dvOffset = data.byteOffset + offset;\n }\n data = data.buffer;\n }\n if (dataIsGiven) {\n this.lastWrittenByte = byteLength;\n } else {\n this.lastWrittenByte = 0;\n }\n this.buffer = data;\n this.length = byteLength;\n this.byteLength = byteLength;\n this.byteOffset = dvOffset;\n this.offset = 0;\n this.littleEndian = true;\n this._data = new DataView(this.buffer, dvOffset, byteLength);\n this._mark = 0;\n this._marks = [];\n }\n\n /**\n * Checks if the memory allocated to the buffer is sufficient to store more\n * bytes after the offset.\n * @param byteLength - The needed memory in bytes.\n * @returns `true` if there is sufficient space and `false` otherwise.\n */\n public available(byteLength = 1): boolean {\n return this.offset + byteLength <= this.length;\n }\n\n /**\n * Check if little-endian mode is used for reading and writing multi-byte\n * values.\n * @returns `true` if little-endian mode is used, `false` otherwise.\n */\n public isLittleEndian(): boolean {\n return this.littleEndian;\n }\n\n /**\n * Set little-endian mode for reading and writing multi-byte values.\n */\n public setLittleEndian(): this {\n this.littleEndian = true;\n return this;\n }\n\n /**\n * Check if big-endian mode is used for reading and writing multi-byte values.\n * @returns `true` if big-endian mode is used, `false` otherwise.\n */\n public isBigEndian(): boolean {\n return !this.littleEndian;\n }\n\n /**\n * Switches to big-endian mode for reading and writing multi-byte values.\n */\n public setBigEndian(): this {\n this.littleEndian = false;\n return this;\n }\n\n /**\n * Move the pointer n bytes forward.\n * @param n - Number of bytes to skip.\n */\n public skip(n = 1): this {\n this.offset += n;\n return this;\n }\n\n /**\n * Move the pointer to the given offset.\n * @param offset\n */\n public seek(offset: number): this {\n this.offset = offset;\n return this;\n }\n\n /**\n * Store the current pointer offset.\n * @see {@link IOBuffer#reset}\n */\n public mark(): this {\n this._mark = this.offset;\n return this;\n }\n\n /**\n * Move the pointer back to the last pointer offset set by mark.\n * @see {@link IOBuffer#mark}\n */\n public reset(): this {\n this.offset = this._mark;\n return this;\n }\n\n /**\n * Push the current pointer offset to the mark stack.\n * @see {@link IOBuffer#popMark}\n */\n public pushMark(): this {\n this._marks.push(this.offset);\n return this;\n }\n\n /**\n * Pop the last pointer offset from the mark stack, and set the current\n * pointer offset to the popped value.\n * @see {@link IOBuffer#pushMark}\n */\n public popMark(): this {\n const offset = this._marks.pop();\n if (offset === undefined) {\n throw new Error('Mark stack empty');\n }\n this.seek(offset);\n return this;\n }\n\n /**\n * Move the pointer offset back to 0.\n */\n public rewind(): this {\n this.offset = 0;\n return this;\n }\n\n /**\n * Make sure the buffer has sufficient memory to write a given byteLength at\n * the current pointer offset.\n * If the buffer's memory is insufficient, this method will create a new\n * buffer (a copy) with a length that is twice (byteLength + current offset).\n * @param byteLength\n */\n public ensureAvailable(byteLength = 1): this {\n if (!this.available(byteLength)) {\n const lengthNeeded = this.offset + byteLength;\n const newLength = lengthNeeded * 2;\n const newArray = new Uint8Array(newLength);\n newArray.set(new Uint8Array(this.buffer));\n this.buffer = newArray.buffer;\n this.length = this.byteLength = newLength;\n this._data = new DataView(this.buffer);\n }\n return this;\n }\n\n /**\n * Read a byte and return false if the byte's value is 0, or true otherwise.\n * Moves pointer forward by one byte.\n */\n public readBoolean(): boolean {\n return this.readUint8() !== 0;\n }\n\n /**\n * Read a signed 8-bit integer and move pointer forward by 1 byte.\n */\n public readInt8(): number {\n return this._data.getInt8(this.offset++);\n }\n\n /**\n * Read an unsigned 8-bit integer and move pointer forward by 1 byte.\n */\n public readUint8(): number {\n return this._data.getUint8(this.offset++);\n }\n\n /**\n * Alias for {@link IOBuffer#readUint8}.\n */\n public readByte(): number {\n return this.readUint8();\n }\n\n /**\n * Read `n` bytes and move pointer forward by `n` bytes.\n */\n public readBytes(n = 1): Uint8Array {\n const bytes = new Uint8Array(n);\n for (let i = 0; i < n; i++) {\n bytes[i] = this.readByte();\n }\n return bytes;\n }\n\n /**\n * Read a 16-bit signed integer and move pointer forward by 2 bytes.\n */\n public readInt16(): number {\n const value = this._data.getInt16(this.offset, this.littleEndian);\n this.offset += 2;\n return value;\n }\n\n /**\n * Read a 16-bit unsigned integer and move pointer forward by 2 bytes.\n */\n public readUint16(): number {\n const value = this._data.getUint16(this.offset, this.littleEndian);\n this.offset += 2;\n return value;\n }\n\n /**\n * Read a 32-bit signed integer and move pointer forward by 4 bytes.\n */\n public readInt32(): number {\n const value = this._data.getInt32(this.offset, this.littleEndian);\n this.offset += 4;\n return value;\n }\n\n /**\n * Read a 32-bit unsigned integer and move pointer forward by 4 bytes.\n */\n public readUint32(): number {\n const value = this._data.getUint32(this.offset, this.littleEndian);\n this.offset += 4;\n return value;\n }\n\n /**\n * Read a 32-bit floating number and move pointer forward by 4 bytes.\n */\n public readFloat32(): number {\n const value = this._data.getFloat32(this.offset, this.littleEndian);\n this.offset += 4;\n return value;\n }\n\n /**\n * Read a 64-bit floating number and move pointer forward by 8 bytes.\n */\n public readFloat64(): number {\n const value = this._data.getFloat64(this.offset, this.littleEndian);\n this.offset += 8;\n return value;\n }\n\n /**\n * Read a 1-byte ASCII character and move pointer forward by 1 byte.\n */\n public readChar(): string {\n return String.fromCharCode(this.readInt8());\n }\n\n /**\n * Read `n` 1-byte ASCII characters and move pointer forward by `n` bytes.\n */\n public readChars(n = 1): string {\n let result = '';\n for (let i = 0; i < n; i++) {\n result += this.readChar();\n }\n return result;\n }\n\n /**\n * Read the next `n` bytes, return a UTF-8 decoded string and move pointer\n * forward by `n` bytes.\n */\n public readUtf8(n = 1): string {\n return this.textDecoder.decode(this.readBytes(n));\n }\n\n /**\n * Write 0xff if the passed value is truthy, 0x00 otherwise and move pointer\n * forward by 1 byte.\n */\n public writeBoolean(value: unknown): this {\n this.writeUint8(value ? 0xff : 0x00);\n return this;\n }\n\n /**\n * Write `value` as an 8-bit signed integer and move pointer forward by 1 byte.\n */\n public writeInt8(value: number): this {\n this.ensureAvailable(1);\n this._data.setInt8(this.offset++, value);\n this._updateLastWrittenByte();\n return this;\n }\n\n /**\n * Write `value` as an 8-bit unsigned integer and move pointer forward by 1\n * byte.\n */\n public writeUint8(value: number): this {\n this.ensureAvailable(1);\n this._data.setUint8(this.offset++, value);\n this._updateLastWrittenByte();\n return this;\n }\n\n /**\n * An alias for {@link IOBuffer#writeUint8}.\n */\n public writeByte(value: number): this {\n return this.writeUint8(value);\n }\n\n /**\n * Write all elements of `bytes` as uint8 values and move pointer forward by\n * `bytes.length` bytes.\n */\n public writeBytes(bytes: ArrayLike<number>): this {\n this.ensureAvailable(bytes.length);\n for (let i = 0; i < bytes.length; i++) {\n this._data.setUint8(this.offset++, bytes[i]);\n }\n this._updateLastWrittenByte();\n return this;\n }\n\n /**\n * Write `value` as a 16-bit signed integer and move pointer forward by 2\n * bytes.\n */\n public writeInt16(value: number): this {\n this.ensureAvailable(2);\n this._data.setInt16(this.offset, value, this.littleEndian);\n this.offset += 2;\n this._updateLastWrittenByte();\n return this;\n }\n\n /**\n * Write `value` as a 16-bit unsigned integer and move pointer forward by 2\n * bytes.\n */\n public writeUint16(value: number): this {\n this.ensureAvailable(2);\n this._data.setUint16(this.offset, value, this.littleEndian);\n this.offset += 2;\n this._updateLastWrittenByte();\n return this;\n }\n\n /**\n * Write `value` as a 32-bit signed integer and move pointer forward by 4\n * bytes.\n */\n public writeInt32(value: number): this {\n this.ensureAvailable(4);\n this._data.setInt32(this.offset, value, this.littleEndian);\n this.offset += 4;\n this._updateLastWrittenByte();\n return this;\n }\n\n /**\n * Write `value` as a 32-bit unsigned integer and move pointer forward by 4\n * bytes.\n */\n public writeUint32(value: number): this {\n this.ensureAvailable(4);\n this._data.setUint32(this.offset, value, this.littleEndian);\n this.offset += 4;\n this._updateLastWrittenByte();\n return this;\n }\n\n /**\n * Write `value` as a 32-bit floating number and move pointer forward by 4\n * bytes.\n */\n public writeFloat32(value: number): this {\n this.ensureAvailable(4);\n this._data.setFloat32(this.offset, value, this.littleEndian);\n this.offset += 4;\n this._updateLastWrittenByte();\n return this;\n }\n\n /**\n * Write `value` as a 64-bit floating number and move pointer forward by 8\n * bytes.\n */\n public writeFloat64(value: number): this {\n this.ensureAvailable(8);\n this._data.setFloat64(this.offset, value, this.littleEndian);\n this.offset += 8;\n this._updateLastWrittenByte();\n return this;\n }\n\n /**\n * Write the charCode of `str`'s first character as an 8-bit unsigned integer\n * and move pointer forward by 1 byte.\n */\n public writeChar(str: string): this {\n return this.writeUint8(str.charCodeAt(0));\n }\n\n /**\n * Write the charCodes of all `str`'s characters as 8-bit unsigned integers\n * and move pointer forward by `str.length` bytes.\n */\n public writeChars(str: string): this {\n for (let i = 0; i < str.length; i++) {\n this.writeUint8(str.charCodeAt(i));\n }\n return this;\n }\n\n /**\n * UTF-8 encode and write `str` to the current pointer offset and move pointer\n * forward according to the encoded length.\n */\n public writeUtf8(str: string): this {\n const bytes = this.textEncoder.encode(str);\n return this.writeBytes(bytes);\n }\n\n /**\n * Export a Uint8Array view of the internal buffer.\n * The view starts at the byte offset and its length\n * is calculated to stop at the last written byte or the original length.\n */\n public toArray(): Uint8Array {\n return new Uint8Array(this.buffer, this.byteOffset, this.lastWrittenByte);\n }\n\n /**\n * Update the last written byte offset\n * @private\n */\n private _updateLastWrittenByte(): void {\n if (this.offset > this.lastWrittenByte) {\n this.lastWrittenByte = this.offset;\n }\n }\n}\n"],"file":"iobuffer.js"}
|
|
1
|
+
{"version":3,"file":"iobuffer.js","names":["DEFAULT_BYTE_LENGTH","IOBuffer","constructor","data","options","TextDecoder","TextEncoder","dataIsGiven","ArrayBuffer","lastWrittenByte","byteLength","offset","dvOffset","isView","buffer","byteOffset","length","littleEndian","_data","DataView","_mark","_marks","available","isLittleEndian","setLittleEndian","isBigEndian","setBigEndian","skip","n","seek","mark","reset","pushMark","push","popMark","pop","undefined","Error","rewind","ensureAvailable","lengthNeeded","newLength","newArray","Uint8Array","set","readBoolean","readUint8","readInt8","getInt8","getUint8","readByte","readBytes","bytes","i","readInt16","value","getInt16","readUint16","getUint16","readInt32","getInt32","readUint32","getUint32","readFloat32","getFloat32","readFloat64","getFloat64","readChar","String","fromCharCode","readChars","result","readUtf8","textDecoder","decode","writeBoolean","writeUint8","writeInt8","setInt8","_updateLastWrittenByte","setUint8","writeByte","writeBytes","writeInt16","setInt16","writeUint16","setUint16","writeInt32","setInt32","writeUint32","setUint32","writeFloat32","setFloat32","writeFloat64","setFloat64","writeChar","str","charCodeAt","writeChars","writeUtf8","textEncoder","encode","toArray"],"sources":["../../../src/iobuffer/iobuffer.ts"],"sourcesContent":["const DEFAULT_BYTE_LENGTH = 1024 * 8;\n\ntype InputData = number | ArrayBufferLike | ArrayBufferView | IOBuffer | Buffer;\n\ninterface IOBufferOptions {\n /**\n * Ignore the first n bytes of the ArrayBuffer.\n */\n offset?: number;\n}\n\nexport class IOBuffer {\n /**\n * Reference to the internal ArrayBuffer object.\n */\n public buffer: ArrayBufferLike;\n\n /**\n * Byte length of the internal ArrayBuffer.\n */\n public byteLength: number;\n\n /**\n * Byte offset of the internal ArrayBuffer.\n */\n public byteOffset: number;\n\n /**\n * Byte length of the internal ArrayBuffer.\n */\n public length: number;\n\n /**\n * The current offset of the buffer's pointer.\n */\n public offset: number;\n\n private lastWrittenByte: number;\n private littleEndian: boolean;\n\n private _data: DataView;\n private _mark: number;\n private _marks: number[];\n\n private textDecoder = new TextDecoder();\n private textEncoder = new TextEncoder();\n\n /**\n * @param data - The data to construct the IOBuffer with.\n * If data is a number, it will be the new buffer's length<br>\n * If data is `undefined`, the buffer will be initialized with a default length of 8Kb<br>\n * If data is an ArrayBuffer, SharedArrayBuffer, an ArrayBufferView (Typed Array), an IOBuffer instance,\n * or a Node.js Buffer, a view will be created over the underlying ArrayBuffer.\n * @param options\n */\n public constructor(data: InputData = DEFAULT_BYTE_LENGTH, options: IOBufferOptions = {}) {\n let dataIsGiven = false;\n if (typeof data === 'number') {\n data = new ArrayBuffer(data);\n } else {\n dataIsGiven = true;\n this.lastWrittenByte = data.byteLength;\n }\n\n const offset = options.offset ? options.offset >>> 0 : 0;\n const byteLength = data.byteLength - offset;\n let dvOffset = offset;\n if (ArrayBuffer.isView(data) || data instanceof IOBuffer) {\n if (data.byteLength !== data.buffer.byteLength) {\n dvOffset = data.byteOffset + offset;\n }\n data = data.buffer;\n }\n if (dataIsGiven) {\n this.lastWrittenByte = byteLength;\n } else {\n this.lastWrittenByte = 0;\n }\n this.buffer = data;\n this.length = byteLength;\n this.byteLength = byteLength;\n this.byteOffset = dvOffset;\n this.offset = 0;\n this.littleEndian = true;\n this._data = new DataView(this.buffer, dvOffset, byteLength);\n this._mark = 0;\n this._marks = [];\n }\n\n /**\n * Checks if the memory allocated to the buffer is sufficient to store more\n * bytes after the offset.\n * @param byteLength - The needed memory in bytes.\n * @returns `true` if there is sufficient space and `false` otherwise.\n */\n public available(byteLength = 1): boolean {\n return this.offset + byteLength <= this.length;\n }\n\n /**\n * Check if little-endian mode is used for reading and writing multi-byte\n * values.\n * @returns `true` if little-endian mode is used, `false` otherwise.\n */\n public isLittleEndian(): boolean {\n return this.littleEndian;\n }\n\n /**\n * Set little-endian mode for reading and writing multi-byte values.\n */\n public setLittleEndian(): this {\n this.littleEndian = true;\n return this;\n }\n\n /**\n * Check if big-endian mode is used for reading and writing multi-byte values.\n * @returns `true` if big-endian mode is used, `false` otherwise.\n */\n public isBigEndian(): boolean {\n return !this.littleEndian;\n }\n\n /**\n * Switches to big-endian mode for reading and writing multi-byte values.\n */\n public setBigEndian(): this {\n this.littleEndian = false;\n return this;\n }\n\n /**\n * Move the pointer n bytes forward.\n * @param n - Number of bytes to skip.\n */\n public skip(n = 1): this {\n this.offset += n;\n return this;\n }\n\n /**\n * Move the pointer to the given offset.\n * @param offset\n */\n public seek(offset: number): this {\n this.offset = offset;\n return this;\n }\n\n /**\n * Store the current pointer offset.\n * @see {@link IOBuffer#reset}\n */\n public mark(): this {\n this._mark = this.offset;\n return this;\n }\n\n /**\n * Move the pointer back to the last pointer offset set by mark.\n * @see {@link IOBuffer#mark}\n */\n public reset(): this {\n this.offset = this._mark;\n return this;\n }\n\n /**\n * Push the current pointer offset to the mark stack.\n * @see {@link IOBuffer#popMark}\n */\n public pushMark(): this {\n this._marks.push(this.offset);\n return this;\n }\n\n /**\n * Pop the last pointer offset from the mark stack, and set the current\n * pointer offset to the popped value.\n * @see {@link IOBuffer#pushMark}\n */\n public popMark(): this {\n const offset = this._marks.pop();\n if (offset === undefined) {\n throw new Error('Mark stack empty');\n }\n this.seek(offset);\n return this;\n }\n\n /**\n * Move the pointer offset back to 0.\n */\n public rewind(): this {\n this.offset = 0;\n return this;\n }\n\n /**\n * Make sure the buffer has sufficient memory to write a given byteLength at\n * the current pointer offset.\n * If the buffer's memory is insufficient, this method will create a new\n * buffer (a copy) with a length that is twice (byteLength + current offset).\n * @param byteLength\n */\n public ensureAvailable(byteLength = 1): this {\n if (!this.available(byteLength)) {\n const lengthNeeded = this.offset + byteLength;\n const newLength = lengthNeeded * 2;\n const newArray = new Uint8Array(newLength);\n newArray.set(new Uint8Array(this.buffer));\n this.buffer = newArray.buffer;\n this.length = this.byteLength = newLength;\n this._data = new DataView(this.buffer);\n }\n return this;\n }\n\n /**\n * Read a byte and return false if the byte's value is 0, or true otherwise.\n * Moves pointer forward by one byte.\n */\n public readBoolean(): boolean {\n return this.readUint8() !== 0;\n }\n\n /**\n * Read a signed 8-bit integer and move pointer forward by 1 byte.\n */\n public readInt8(): number {\n return this._data.getInt8(this.offset++);\n }\n\n /**\n * Read an unsigned 8-bit integer and move pointer forward by 1 byte.\n */\n public readUint8(): number {\n return this._data.getUint8(this.offset++);\n }\n\n /**\n * Alias for {@link IOBuffer#readUint8}.\n */\n public readByte(): number {\n return this.readUint8();\n }\n\n /**\n * Read `n` bytes and move pointer forward by `n` bytes.\n */\n public readBytes(n = 1): Uint8Array {\n const bytes = new Uint8Array(n);\n for (let i = 0; i < n; i++) {\n bytes[i] = this.readByte();\n }\n return bytes;\n }\n\n /**\n * Read a 16-bit signed integer and move pointer forward by 2 bytes.\n */\n public readInt16(): number {\n const value = this._data.getInt16(this.offset, this.littleEndian);\n this.offset += 2;\n return value;\n }\n\n /**\n * Read a 16-bit unsigned integer and move pointer forward by 2 bytes.\n */\n public readUint16(): number {\n const value = this._data.getUint16(this.offset, this.littleEndian);\n this.offset += 2;\n return value;\n }\n\n /**\n * Read a 32-bit signed integer and move pointer forward by 4 bytes.\n */\n public readInt32(): number {\n const value = this._data.getInt32(this.offset, this.littleEndian);\n this.offset += 4;\n return value;\n }\n\n /**\n * Read a 32-bit unsigned integer and move pointer forward by 4 bytes.\n */\n public readUint32(): number {\n const value = this._data.getUint32(this.offset, this.littleEndian);\n this.offset += 4;\n return value;\n }\n\n /**\n * Read a 32-bit floating number and move pointer forward by 4 bytes.\n */\n public readFloat32(): number {\n const value = this._data.getFloat32(this.offset, this.littleEndian);\n this.offset += 4;\n return value;\n }\n\n /**\n * Read a 64-bit floating number and move pointer forward by 8 bytes.\n */\n public readFloat64(): number {\n const value = this._data.getFloat64(this.offset, this.littleEndian);\n this.offset += 8;\n return value;\n }\n\n /**\n * Read a 1-byte ASCII character and move pointer forward by 1 byte.\n */\n public readChar(): string {\n return String.fromCharCode(this.readInt8());\n }\n\n /**\n * Read `n` 1-byte ASCII characters and move pointer forward by `n` bytes.\n */\n public readChars(n = 1): string {\n let result = '';\n for (let i = 0; i < n; i++) {\n result += this.readChar();\n }\n return result;\n }\n\n /**\n * Read the next `n` bytes, return a UTF-8 decoded string and move pointer\n * forward by `n` bytes.\n */\n public readUtf8(n = 1): string {\n return this.textDecoder.decode(this.readBytes(n));\n }\n\n /**\n * Write 0xff if the passed value is truthy, 0x00 otherwise and move pointer\n * forward by 1 byte.\n */\n public writeBoolean(value: unknown): this {\n this.writeUint8(value ? 0xff : 0x00);\n return this;\n }\n\n /**\n * Write `value` as an 8-bit signed integer and move pointer forward by 1 byte.\n */\n public writeInt8(value: number): this {\n this.ensureAvailable(1);\n this._data.setInt8(this.offset++, value);\n this._updateLastWrittenByte();\n return this;\n }\n\n /**\n * Write `value` as an 8-bit unsigned integer and move pointer forward by 1\n * byte.\n */\n public writeUint8(value: number): this {\n this.ensureAvailable(1);\n this._data.setUint8(this.offset++, value);\n this._updateLastWrittenByte();\n return this;\n }\n\n /**\n * An alias for {@link IOBuffer#writeUint8}.\n */\n public writeByte(value: number): this {\n return this.writeUint8(value);\n }\n\n /**\n * Write all elements of `bytes` as uint8 values and move pointer forward by\n * `bytes.length` bytes.\n */\n public writeBytes(bytes: ArrayLike<number>): this {\n this.ensureAvailable(bytes.length);\n for (let i = 0; i < bytes.length; i++) {\n this._data.setUint8(this.offset++, bytes[i]);\n }\n this._updateLastWrittenByte();\n return this;\n }\n\n /**\n * Write `value` as a 16-bit signed integer and move pointer forward by 2\n * bytes.\n */\n public writeInt16(value: number): this {\n this.ensureAvailable(2);\n this._data.setInt16(this.offset, value, this.littleEndian);\n this.offset += 2;\n this._updateLastWrittenByte();\n return this;\n }\n\n /**\n * Write `value` as a 16-bit unsigned integer and move pointer forward by 2\n * bytes.\n */\n public writeUint16(value: number): this {\n this.ensureAvailable(2);\n this._data.setUint16(this.offset, value, this.littleEndian);\n this.offset += 2;\n this._updateLastWrittenByte();\n return this;\n }\n\n /**\n * Write `value` as a 32-bit signed integer and move pointer forward by 4\n * bytes.\n */\n public writeInt32(value: number): this {\n this.ensureAvailable(4);\n this._data.setInt32(this.offset, value, this.littleEndian);\n this.offset += 4;\n this._updateLastWrittenByte();\n return this;\n }\n\n /**\n * Write `value` as a 32-bit unsigned integer and move pointer forward by 4\n * bytes.\n */\n public writeUint32(value: number): this {\n this.ensureAvailable(4);\n this._data.setUint32(this.offset, value, this.littleEndian);\n this.offset += 4;\n this._updateLastWrittenByte();\n return this;\n }\n\n /**\n * Write `value` as a 32-bit floating number and move pointer forward by 4\n * bytes.\n */\n public writeFloat32(value: number): this {\n this.ensureAvailable(4);\n this._data.setFloat32(this.offset, value, this.littleEndian);\n this.offset += 4;\n this._updateLastWrittenByte();\n return this;\n }\n\n /**\n * Write `value` as a 64-bit floating number and move pointer forward by 8\n * bytes.\n */\n public writeFloat64(value: number): this {\n this.ensureAvailable(8);\n this._data.setFloat64(this.offset, value, this.littleEndian);\n this.offset += 8;\n this._updateLastWrittenByte();\n return this;\n }\n\n /**\n * Write the charCode of `str`'s first character as an 8-bit unsigned integer\n * and move pointer forward by 1 byte.\n */\n public writeChar(str: string): this {\n return this.writeUint8(str.charCodeAt(0));\n }\n\n /**\n * Write the charCodes of all `str`'s characters as 8-bit unsigned integers\n * and move pointer forward by `str.length` bytes.\n */\n public writeChars(str: string): this {\n for (let i = 0; i < str.length; i++) {\n this.writeUint8(str.charCodeAt(i));\n }\n return this;\n }\n\n /**\n * UTF-8 encode and write `str` to the current pointer offset and move pointer\n * forward according to the encoded length.\n */\n public writeUtf8(str: string): this {\n const bytes = this.textEncoder.encode(str);\n return this.writeBytes(bytes);\n }\n\n /**\n * Export a Uint8Array view of the internal buffer.\n * The view starts at the byte offset and its length\n * is calculated to stop at the last written byte or the original length.\n */\n public toArray(): Uint8Array {\n return new Uint8Array(this.buffer, this.byteOffset, this.lastWrittenByte);\n }\n\n /**\n * Update the last written byte offset\n * @private\n */\n private _updateLastWrittenByte(): void {\n if (this.offset > this.lastWrittenByte) {\n this.lastWrittenByte = this.offset;\n }\n }\n}\n"],"mappings":";AAAA,MAAMA,mBAAmB,GAAG,IAAI,GAAG,CAAC;AAWpC,OAAO,MAAMC,QAAQ,CAAC;;EA4CbC,WAAW,GAAuE;IAAA,IAAtEC,IAAe,uEAAGH,mBAAmB;IAAA,IAAEI,OAAwB,uEAAG,CAAC,CAAC;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA,qCAXjE,IAAIC,WAAW,EAAE;IAAA,qCACjB,IAAIC,WAAW,EAAE;IAWrC,IAAIC,WAAW,GAAG,KAAK;IACvB,IAAI,OAAOJ,IAAI,KAAK,QAAQ,EAAE;MAC5BA,IAAI,GAAG,IAAIK,WAAW,CAACL,IAAI,CAAC;IAC9B,CAAC,MAAM;MACLI,WAAW,GAAG,IAAI;MAClB,IAAI,CAACE,eAAe,GAAGN,IAAI,CAACO,UAAU;IACxC;IAEA,MAAMC,MAAM,GAAGP,OAAO,CAACO,MAAM,GAAGP,OAAO,CAACO,MAAM,KAAK,CAAC,GAAG,CAAC;IACxD,MAAMD,UAAU,GAAGP,IAAI,CAACO,UAAU,GAAGC,MAAM;IAC3C,IAAIC,QAAQ,GAAGD,MAAM;IACrB,IAAIH,WAAW,CAACK,MAAM,CAACV,IAAI,CAAC,IAAIA,IAAI,YAAYF,QAAQ,EAAE;MACxD,IAAIE,IAAI,CAACO,UAAU,KAAKP,IAAI,CAACW,MAAM,CAACJ,UAAU,EAAE;QAC9CE,QAAQ,GAAGT,IAAI,CAACY,UAAU,GAAGJ,MAAM;MACrC;MACAR,IAAI,GAAGA,IAAI,CAACW,MAAM;IACpB;IACA,IAAIP,WAAW,EAAE;MACf,IAAI,CAACE,eAAe,GAAGC,UAAU;IACnC,CAAC,MAAM;MACL,IAAI,CAACD,eAAe,GAAG,CAAC;IAC1B;IACA,IAA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