@loaders.gl/netcdf 4.0.0-alpha.4 → 4.0.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 +20 -0
- package/dist/es5/index.js.map +1 -0
- package/dist/es5/iobuffer/iobuffer.js +369 -0
- package/dist/es5/iobuffer/iobuffer.js.map +1 -0
- package/dist/es5/netcdf-loader.js +81 -0
- package/dist/es5/netcdf-loader.js.map +1 -0
- package/dist/es5/netcdfjs/netcdf-reader.js +173 -0
- package/dist/es5/netcdfjs/netcdf-reader.js.map +1 -0
- package/dist/es5/netcdfjs/netcdf-types.js +2 -0
- package/dist/es5/netcdfjs/netcdf-types.js.map +1 -0
- package/dist/es5/netcdfjs/read-data.js +31 -0
- package/dist/es5/netcdfjs/read-data.js.map +1 -0
- package/dist/es5/netcdfjs/read-header.js +168 -0
- package/dist/es5/netcdfjs/read-header.js.map +1 -0
- package/dist/es5/netcdfjs/read-type.js +108 -0
- package/dist/es5/netcdfjs/read-type.js.map +1 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/iobuffer/iobuffer.js +270 -0
- package/dist/esm/iobuffer/iobuffer.js.map +1 -0
- package/dist/esm/netcdf-loader.js +38 -0
- package/dist/esm/netcdf-loader.js.map +1 -0
- package/dist/esm/netcdfjs/LICENSE +24 -0
- package/dist/esm/netcdfjs/netcdf-reader.js +104 -0
- package/dist/esm/netcdfjs/netcdf-reader.js.map +1 -0
- package/dist/esm/netcdfjs/netcdf-types.js +2 -0
- package/dist/esm/netcdfjs/netcdf-types.js.map +1 -0
- package/dist/esm/netcdfjs/read-data.js +24 -0
- package/dist/esm/netcdfjs/read-data.js.map +1 -0
- package/dist/esm/netcdfjs/read-header.js +161 -0
- package/dist/esm/netcdfjs/read-header.js.map +1 -0
- package/dist/esm/netcdfjs/read-type.js +97 -0
- package/dist/esm/netcdfjs/read-type.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -3
- package/dist/iobuffer/iobuffer.d.ts +254 -0
- package/dist/iobuffer/iobuffer.d.ts.map +1 -0
- package/dist/iobuffer/iobuffer.js +425 -370
- package/dist/netcdf-loader.d.ts +52 -0
- package/dist/netcdf-loader.d.ts.map +1 -0
- package/dist/netcdf-loader.js +46 -36
- package/dist/netcdfjs/netcdf-reader.d.ts +68 -0
- package/dist/netcdfjs/netcdf-reader.d.ts.map +1 -0
- package/dist/netcdfjs/netcdf-reader.js +155 -126
- package/dist/netcdfjs/netcdf-types.d.ts +70 -0
- package/dist/netcdfjs/netcdf-types.d.ts.map +1 -0
- package/dist/netcdfjs/netcdf-types.js +2 -2
- package/dist/netcdfjs/read-data.d.ts +18 -0
- package/dist/netcdfjs/read-data.d.ts.map +1 -0
- package/dist/netcdfjs/read-data.js +47 -26
- package/dist/netcdfjs/read-header.d.ts +16 -0
- package/dist/netcdfjs/read-header.d.ts.map +1 -0
- package/dist/netcdfjs/read-header.js +206 -173
- package/dist/netcdfjs/read-type.d.ts +36 -0
- package/dist/netcdfjs/read-type.d.ts.map +1 -0
- package/dist/netcdfjs/read-type.js +130 -117
- package/package.json +7 -7
- package/dist/index.js.map +0 -1
- package/dist/iobuffer/iobuffer.js.map +0 -1
- package/dist/netcdf-loader.js.map +0 -1
- package/dist/netcdfjs/netcdf-reader.js.map +0 -1
- package/dist/netcdfjs/netcdf-types.js.map +0 -1
- package/dist/netcdfjs/read-data.js.map +0 -1
- package/dist/netcdfjs/read-header.js.map +0 -1
- package/dist/netcdfjs/read-type.js.map +0 -1
- /package/dist/{netcdfjs → es5/netcdfjs}/LICENSE +0 -0
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { readType, num2str } from './read-type';
|
|
2
|
+
const ZERO = 0;
|
|
3
|
+
const NC_DIMENSION = 10;
|
|
4
|
+
const NC_VARIABLE = 11;
|
|
5
|
+
const NC_ATTRIBUTE = 12;
|
|
6
|
+
const NC_UNLIMITED = 0;
|
|
7
|
+
export function readNetCDFHeader(buffer, version) {
|
|
8
|
+
const recordDimensionLength = buffer.readUint32();
|
|
9
|
+
const dimList = readDimensionsList(buffer);
|
|
10
|
+
const attributes = readAttributesList(buffer);
|
|
11
|
+
const variableList = readVariablesList(buffer, dimList.recordId, version);
|
|
12
|
+
const header = {
|
|
13
|
+
version,
|
|
14
|
+
recordDimension: {
|
|
15
|
+
length: recordDimensionLength,
|
|
16
|
+
id: dimList.recordId,
|
|
17
|
+
name: dimList.recordName,
|
|
18
|
+
recordStep: variableList.recordStep
|
|
19
|
+
},
|
|
20
|
+
dimensions: dimList.dimensions,
|
|
21
|
+
variables: variableList.variables,
|
|
22
|
+
attributes
|
|
23
|
+
};
|
|
24
|
+
return header;
|
|
25
|
+
}
|
|
26
|
+
function readDimensionsList(buffer) {
|
|
27
|
+
const dimList = buffer.readUint32();
|
|
28
|
+
if (dimList === ZERO) {
|
|
29
|
+
if (buffer.readUint32() !== ZERO) {
|
|
30
|
+
throw new Error('NetCDF: wrong empty tag for list of dimensions');
|
|
31
|
+
}
|
|
32
|
+
return {
|
|
33
|
+
recordId: 0,
|
|
34
|
+
recordName: '',
|
|
35
|
+
dimensions: []
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
if (dimList !== NC_DIMENSION) {
|
|
39
|
+
throw new Error('NetCDF: wrong tag for list of dimensions');
|
|
40
|
+
}
|
|
41
|
+
const dimensionSize = buffer.readUint32();
|
|
42
|
+
const dimensions = new Array(dimensionSize);
|
|
43
|
+
let recordId;
|
|
44
|
+
let recordName;
|
|
45
|
+
for (let dim = 0; dim < dimensionSize; dim++) {
|
|
46
|
+
const name = readName(buffer);
|
|
47
|
+
const size = buffer.readUint32();
|
|
48
|
+
if (size === NC_UNLIMITED) {
|
|
49
|
+
recordId = dim;
|
|
50
|
+
recordName = name;
|
|
51
|
+
}
|
|
52
|
+
dimensions[dim] = {
|
|
53
|
+
name,
|
|
54
|
+
size
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
return {
|
|
58
|
+
dimensions,
|
|
59
|
+
recordId,
|
|
60
|
+
recordName
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
function readAttributesList(buffer) {
|
|
64
|
+
const gAttList = buffer.readUint32();
|
|
65
|
+
if (gAttList === ZERO) {
|
|
66
|
+
if (buffer.readUint32() !== ZERO) {
|
|
67
|
+
throw new Error('NetCDF: wrong empty tag for list of attributes');
|
|
68
|
+
}
|
|
69
|
+
return [];
|
|
70
|
+
}
|
|
71
|
+
if (gAttList !== NC_ATTRIBUTE) {
|
|
72
|
+
throw new Error('NetCDF: wrong tag for list of attributes');
|
|
73
|
+
}
|
|
74
|
+
const attributeSize = buffer.readUint32();
|
|
75
|
+
const attributes = new Array(attributeSize);
|
|
76
|
+
for (let gAtt = 0; gAtt < attributeSize; gAtt++) {
|
|
77
|
+
const name = readName(buffer);
|
|
78
|
+
const type = buffer.readUint32();
|
|
79
|
+
if (type < 1 || type > 6) {
|
|
80
|
+
throw new Error("NetCDF: non valid type ".concat(type));
|
|
81
|
+
}
|
|
82
|
+
const size = buffer.readUint32();
|
|
83
|
+
const value = readType(buffer, type, size);
|
|
84
|
+
padding(buffer);
|
|
85
|
+
attributes[gAtt] = {
|
|
86
|
+
name,
|
|
87
|
+
type: num2str(type),
|
|
88
|
+
value
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
return attributes;
|
|
92
|
+
}
|
|
93
|
+
function readVariablesList(buffer, recordId, version) {
|
|
94
|
+
const varList = buffer.readUint32();
|
|
95
|
+
let recordStep = 0;
|
|
96
|
+
if (varList === ZERO) {
|
|
97
|
+
if (buffer.readUint32() !== ZERO) {
|
|
98
|
+
throw new Error('NetCDF: wrong empty tag for list of variables');
|
|
99
|
+
}
|
|
100
|
+
return {
|
|
101
|
+
recordStep,
|
|
102
|
+
variables: []
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
if (varList !== NC_VARIABLE) {
|
|
106
|
+
throw new Error('NetCDF: wrong tag for list of variables');
|
|
107
|
+
}
|
|
108
|
+
const variableSize = buffer.readUint32();
|
|
109
|
+
const variables = new Array(variableSize);
|
|
110
|
+
for (let v = 0; v < variableSize; v++) {
|
|
111
|
+
const name = readName(buffer);
|
|
112
|
+
const dimensionality = buffer.readUint32();
|
|
113
|
+
const dimensionsIds = new Array(dimensionality);
|
|
114
|
+
for (let dim = 0; dim < dimensionality; dim++) {
|
|
115
|
+
dimensionsIds[dim] = buffer.readUint32();
|
|
116
|
+
}
|
|
117
|
+
const attributes = readAttributesList(buffer);
|
|
118
|
+
const type = buffer.readUint32();
|
|
119
|
+
if (type < 1 && type > 6) {
|
|
120
|
+
throw new Error("NetCDF: non valid type ".concat(type));
|
|
121
|
+
}
|
|
122
|
+
const varSize = buffer.readUint32();
|
|
123
|
+
let offset = buffer.readUint32();
|
|
124
|
+
if (version === 2) {
|
|
125
|
+
if (offset > 0) {
|
|
126
|
+
throw new Error('NetCDF: offsets larger than 4GB not supported');
|
|
127
|
+
}
|
|
128
|
+
offset = buffer.readUint32();
|
|
129
|
+
}
|
|
130
|
+
let record = false;
|
|
131
|
+
if (typeof recordId !== 'undefined' && dimensionsIds[0] === recordId) {
|
|
132
|
+
recordStep += varSize;
|
|
133
|
+
record = true;
|
|
134
|
+
}
|
|
135
|
+
variables[v] = {
|
|
136
|
+
name,
|
|
137
|
+
dimensions: dimensionsIds,
|
|
138
|
+
attributes,
|
|
139
|
+
type: num2str(type),
|
|
140
|
+
size: varSize,
|
|
141
|
+
offset,
|
|
142
|
+
record
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
return {
|
|
146
|
+
variables,
|
|
147
|
+
recordStep
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
export function readName(buffer) {
|
|
151
|
+
const nameLength = buffer.readUint32();
|
|
152
|
+
const name = buffer.readChars(nameLength);
|
|
153
|
+
padding(buffer);
|
|
154
|
+
return name;
|
|
155
|
+
}
|
|
156
|
+
function padding(buffer) {
|
|
157
|
+
if (buffer.offset % 4 !== 0) {
|
|
158
|
+
buffer.skip(4 - buffer.offset % 4);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
//# sourceMappingURL=read-header.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read-header.js","names":["readType","num2str","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","concat","value","padding","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,SAAQA,QAAQ,EAAEC,OAAO,QAAO,aAAa;AAG7C,MAAMC,IAAI,GAAG,CAAC;AACd,MAAMC,YAAY,GAAG,EAAE;AACvB,MAAMC,WAAW,GAAG,EAAE;AACtB,MAAMC,YAAY,GAAG,EAAE;AAEvB,MAAMC,YAAY,GAAG,CAAC;AAQtB,OAAO,SAASC,gBAAgBA,CAACC,MAAgB,EAAEC,OAAe,EAAgB;EAGhF,MAAMC,qBAAqB,GAAGF,MAAM,CAACG,UAAU,CAAC,CAAC;EAGjD,MAAMC,OAAO,GAAGC,kBAAkB,CAACL,MAAM,CAAC;EAG1C,MAAMM,UAAU,GAAGC,kBAAkB,CAACP,MAAM,CAAC;EAG7C,MAAMQ,YAAY,GAAGC,iBAAiB,CAACT,MAAM,EAAEI,OAAO,CAACM,QAAQ,EAAET,OAAO,CAAC;EAEzE,MAAMU,MAAoB,GAAG;IAC3BV,OAAO;IACPW,eAAe,EAAE;MACfC,MAAM,EAAEX,qBAAqB;MAC7BY,EAAE,EAAEV,OAAO,CAACM,QAAQ;MACpBK,IAAI,EAAEX,OAAO,CAACY,UAAU;MACxBC,UAAU,EAAET,YAAY,CAACS;IAC3B,CAAC;IACDC,UAAU,EAAEd,OAAO,CAACc,UAAU;IAC9BC,SAAS,EAAEX,YAAY,CAACW,SAAS;IACjCb;EACF,CAAC;EAED,OAAOK,MAAM;AACf;AAOA,SAAS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,GAAGvC,MAAM,CAACG,UAAU,CAAC,CAAC;IAC9B;IAEA,IAAIqC,MAAM,GAAG,KAAK;IAElB,IAAI,OAAO9B,QAAQ,KAAK,WAAW,IAAI2B,aAAa,CAAC,CAAC,CAAC,KAAK3B,QAAQ,EAAE;MACpEO,UAAU,IAAIqB,OAAO;MACrBE,MAAM,GAAG,IAAI;IACf;IACArB,SAAS,CAACgB,CAAC,CAAC,GAAG;MACbpB,IAAI;MACJG,UAAU,EAAEmB,aAAa;MACzB/B,UAAU;MACVuB,IAAI,EAAEpC,OAAO,CAACoC,IAAI,CAAC;MACnBJ,IAAI,EAAEa,OAAO;MACbC,MAAM;MACNC;IACF,CAAC;EACH;EAEA,OAAO;IACLrB,SAAS;IACTF;EACF,CAAC;AACH;AASA,OAAO,SAASO,QAAQA,CAACxB,MAAgB,EAAU;EAEjD,MAAMyC,UAAU,GAAGzC,MAAM,CAACG,UAAU,CAAC,CAAC;EACtC,MAAMY,IAAI,GAAGf,MAAM,CAAC0C,SAAS,CAACD,UAAU,CAAC;EAMzCT,OAAO,CAAChC,MAAM,CAAC;EACf,OAAOe,IAAI;AACb;AAKA,SAASiB,OAAOA,CAAChC,MAAgB,EAAE;EACjC,IAAIA,MAAM,CAACuC,MAAM,GAAG,CAAC,KAAK,CAAC,EAAE;IAC3BvC,MAAM,CAAC2C,IAAI,CAAC,CAAC,GAAI3C,MAAM,CAACuC,MAAM,GAAG,CAAE,CAAC;EACtC;AACF"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
export const TYPES = {
|
|
2
|
+
BYTE: 1,
|
|
3
|
+
CHAR: 2,
|
|
4
|
+
SHORT: 3,
|
|
5
|
+
INT: 4,
|
|
6
|
+
FLOAT: 5,
|
|
7
|
+
DOUBLE: 6
|
|
8
|
+
};
|
|
9
|
+
export function readType(buffer, type, size) {
|
|
10
|
+
switch (type) {
|
|
11
|
+
case TYPES.BYTE:
|
|
12
|
+
return buffer.readBytes(size);
|
|
13
|
+
case TYPES.CHAR:
|
|
14
|
+
return trimNull(buffer.readChars(size));
|
|
15
|
+
case TYPES.SHORT:
|
|
16
|
+
return readNumber(size, buffer.readInt16.bind(buffer));
|
|
17
|
+
case TYPES.INT:
|
|
18
|
+
return readNumber(size, buffer.readInt32.bind(buffer));
|
|
19
|
+
case TYPES.FLOAT:
|
|
20
|
+
return readNumber(size, buffer.readFloat32.bind(buffer));
|
|
21
|
+
case TYPES.DOUBLE:
|
|
22
|
+
return readNumber(size, buffer.readFloat64.bind(buffer));
|
|
23
|
+
default:
|
|
24
|
+
throw new Error("NetCDF: non valid type ".concat(type));
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export function num2str(type) {
|
|
28
|
+
switch (Number(type)) {
|
|
29
|
+
case TYPES.BYTE:
|
|
30
|
+
return 'byte';
|
|
31
|
+
case TYPES.CHAR:
|
|
32
|
+
return 'char';
|
|
33
|
+
case TYPES.SHORT:
|
|
34
|
+
return 'short';
|
|
35
|
+
case TYPES.INT:
|
|
36
|
+
return 'int';
|
|
37
|
+
case TYPES.FLOAT:
|
|
38
|
+
return 'float';
|
|
39
|
+
case TYPES.DOUBLE:
|
|
40
|
+
return 'double';
|
|
41
|
+
default:
|
|
42
|
+
return 'undefined';
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
export function num2bytes(type) {
|
|
46
|
+
switch (Number(type)) {
|
|
47
|
+
case TYPES.BYTE:
|
|
48
|
+
return 1;
|
|
49
|
+
case TYPES.CHAR:
|
|
50
|
+
return 1;
|
|
51
|
+
case TYPES.SHORT:
|
|
52
|
+
return 2;
|
|
53
|
+
case TYPES.INT:
|
|
54
|
+
return 4;
|
|
55
|
+
case TYPES.FLOAT:
|
|
56
|
+
return 4;
|
|
57
|
+
case TYPES.DOUBLE:
|
|
58
|
+
return 8;
|
|
59
|
+
default:
|
|
60
|
+
return -1;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
export function str2num(type) {
|
|
64
|
+
switch (String(type)) {
|
|
65
|
+
case 'byte':
|
|
66
|
+
return TYPES.BYTE;
|
|
67
|
+
case 'char':
|
|
68
|
+
return TYPES.CHAR;
|
|
69
|
+
case 'short':
|
|
70
|
+
return TYPES.SHORT;
|
|
71
|
+
case 'int':
|
|
72
|
+
return TYPES.INT;
|
|
73
|
+
case 'float':
|
|
74
|
+
return TYPES.FLOAT;
|
|
75
|
+
case 'double':
|
|
76
|
+
return TYPES.DOUBLE;
|
|
77
|
+
default:
|
|
78
|
+
return -1;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
function readNumber(size, bufferReader) {
|
|
82
|
+
if (size !== 1) {
|
|
83
|
+
const numbers = new Array(size);
|
|
84
|
+
for (let i = 0; i < size; i++) {
|
|
85
|
+
numbers[i] = bufferReader();
|
|
86
|
+
}
|
|
87
|
+
return numbers;
|
|
88
|
+
}
|
|
89
|
+
return bufferReader();
|
|
90
|
+
}
|
|
91
|
+
function trimNull(value) {
|
|
92
|
+
if (value.charCodeAt(value.length - 1) === 0) {
|
|
93
|
+
return value.substring(0, value.length - 1);
|
|
94
|
+
}
|
|
95
|
+
return value;
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=read-type.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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","concat","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":"AAEA,OAAO,MAAMA,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;AASD,OAAO,SAASC,QAAQA,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,CAAC,CAAC;IACxD,KAAKR,KAAK,CAACI,GAAG;MACZ,OAAOU,UAAU,CAACJ,IAAI,EAAEF,MAAM,CAACS,SAAS,CAACD,IAAI,CAACR,MAAM,CAAC,CAAC;IACxD,KAAKR,KAAK,CAACK,KAAK;MACd,OAAOS,UAAU,CAACJ,IAAI,EAAEF,MAAM,CAACU,WAAW,CAACF,IAAI,CAACR,MAAM,CAAC,CAAC;IAC1D,KAAKR,KAAK,CAACM,MAAM;MACf,OAAOQ,UAAU,CAACJ,IAAI,EAAEF,MAAM,CAACW,WAAW,CA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AAOJ,KAAK,CAACK,KAAK;IACpB,KAAK,QAAQ;MACX,OAAOL,KAAK,CAACM,MAAM;IAErB;MACE,OAAO,CAAC,CAAC;EACb;AACF;AAQA,SAASQ,UAAUA,CAACJ,IAAY,EAAEiB,YAA0B,EAAqB;EAC/E,IAAIjB,IAAI,KAAK,CAAC,EAAE;IACd,MAAMkB,OAAO,GAAG,IAAIC,KAAK,CAACnB,IAAI,CAAC;IAC/B,KAAK,IAAIoB,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGpB,IAAI,EAAEoB,CAAC,EAAE,EAAE;MAC7BF,OAAO,CAACE,CAAC,CAAC,GAAGH,YAAY,CAAC,CAAC;IAC7B;IACA,OAAOC,OAAO;EAChB;EACA,OAAOD,YAAY,CAAC,CAAC;AACvB;AAOA,SAASf,QAAQA,CAACmB,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/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,0BAA0B,CAAC;AAEtD,OAAO,EAAC,YAAY,EAAC,MAAM,iBAAiB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NetCDFLoader = exports.NetCDFReader = void 0;
|
|
4
|
+
var netcdf_reader_1 = require("./netcdfjs/netcdf-reader");
|
|
5
|
+
Object.defineProperty(exports, "NetCDFReader", { enumerable: true, get: function () { return netcdf_reader_1.NetCDFReader; } });
|
|
6
|
+
var netcdf_loader_1 = require("./netcdf-loader");
|
|
7
|
+
Object.defineProperty(exports, "NetCDFLoader", { enumerable: true, get: function () { return netcdf_loader_1.NetCDFLoader; } });
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
type InputData = number | ArrayBufferLike | ArrayBufferView | IOBuffer | Buffer;
|
|
3
|
+
interface IOBufferOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Ignore the first n bytes of the ArrayBuffer.
|
|
6
|
+
*/
|
|
7
|
+
offset?: number;
|
|
8
|
+
}
|
|
9
|
+
export declare class IOBuffer {
|
|
10
|
+
/**
|
|
11
|
+
* Reference to the internal ArrayBuffer object.
|
|
12
|
+
*/
|
|
13
|
+
buffer: ArrayBufferLike;
|
|
14
|
+
/**
|
|
15
|
+
* Byte length of the internal ArrayBuffer.
|
|
16
|
+
*/
|
|
17
|
+
byteLength: number;
|
|
18
|
+
/**
|
|
19
|
+
* Byte offset of the internal ArrayBuffer.
|
|
20
|
+
*/
|
|
21
|
+
byteOffset: number;
|
|
22
|
+
/**
|
|
23
|
+
* Byte length of the internal ArrayBuffer.
|
|
24
|
+
*/
|
|
25
|
+
length: number;
|
|
26
|
+
/**
|
|
27
|
+
* The current offset of the buffer's pointer.
|
|
28
|
+
*/
|
|
29
|
+
offset: number;
|
|
30
|
+
private lastWrittenByte;
|
|
31
|
+
private littleEndian;
|
|
32
|
+
private _data;
|
|
33
|
+
private _mark;
|
|
34
|
+
private _marks;
|
|
35
|
+
private textDecoder;
|
|
36
|
+
private textEncoder;
|
|
37
|
+
/**
|
|
38
|
+
* @param data - The data to construct the IOBuffer with.
|
|
39
|
+
* If data is a number, it will be the new buffer's length<br>
|
|
40
|
+
* If data is `undefined`, the buffer will be initialized with a default length of 8Kb<br>
|
|
41
|
+
* If data is an ArrayBuffer, SharedArrayBuffer, an ArrayBufferView (Typed Array), an IOBuffer instance,
|
|
42
|
+
* or a Node.js Buffer, a view will be created over the underlying ArrayBuffer.
|
|
43
|
+
* @param options
|
|
44
|
+
*/
|
|
45
|
+
constructor(data?: InputData, options?: IOBufferOptions);
|
|
46
|
+
/**
|
|
47
|
+
* Checks if the memory allocated to the buffer is sufficient to store more
|
|
48
|
+
* bytes after the offset.
|
|
49
|
+
* @param byteLength - The needed memory in bytes.
|
|
50
|
+
* @returns `true` if there is sufficient space and `false` otherwise.
|
|
51
|
+
*/
|
|
52
|
+
available(byteLength?: number): boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Check if little-endian mode is used for reading and writing multi-byte
|
|
55
|
+
* values.
|
|
56
|
+
* @returns `true` if little-endian mode is used, `false` otherwise.
|
|
57
|
+
*/
|
|
58
|
+
isLittleEndian(): boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Set little-endian mode for reading and writing multi-byte values.
|
|
61
|
+
*/
|
|
62
|
+
setLittleEndian(): this;
|
|
63
|
+
/**
|
|
64
|
+
* Check if big-endian mode is used for reading and writing multi-byte values.
|
|
65
|
+
* @returns `true` if big-endian mode is used, `false` otherwise.
|
|
66
|
+
*/
|
|
67
|
+
isBigEndian(): boolean;
|
|
68
|
+
/**
|
|
69
|
+
* Switches to big-endian mode for reading and writing multi-byte values.
|
|
70
|
+
*/
|
|
71
|
+
setBigEndian(): this;
|
|
72
|
+
/**
|
|
73
|
+
* Move the pointer n bytes forward.
|
|
74
|
+
* @param n - Number of bytes to skip.
|
|
75
|
+
*/
|
|
76
|
+
skip(n?: number): this;
|
|
77
|
+
/**
|
|
78
|
+
* Move the pointer to the given offset.
|
|
79
|
+
* @param offset
|
|
80
|
+
*/
|
|
81
|
+
seek(offset: number): this;
|
|
82
|
+
/**
|
|
83
|
+
* Store the current pointer offset.
|
|
84
|
+
* @see {@link IOBuffer#reset}
|
|
85
|
+
*/
|
|
86
|
+
mark(): this;
|
|
87
|
+
/**
|
|
88
|
+
* Move the pointer back to the last pointer offset set by mark.
|
|
89
|
+
* @see {@link IOBuffer#mark}
|
|
90
|
+
*/
|
|
91
|
+
reset(): this;
|
|
92
|
+
/**
|
|
93
|
+
* Push the current pointer offset to the mark stack.
|
|
94
|
+
* @see {@link IOBuffer#popMark}
|
|
95
|
+
*/
|
|
96
|
+
pushMark(): this;
|
|
97
|
+
/**
|
|
98
|
+
* Pop the last pointer offset from the mark stack, and set the current
|
|
99
|
+
* pointer offset to the popped value.
|
|
100
|
+
* @see {@link IOBuffer#pushMark}
|
|
101
|
+
*/
|
|
102
|
+
popMark(): this;
|
|
103
|
+
/**
|
|
104
|
+
* Move the pointer offset back to 0.
|
|
105
|
+
*/
|
|
106
|
+
rewind(): this;
|
|
107
|
+
/**
|
|
108
|
+
* Make sure the buffer has sufficient memory to write a given byteLength at
|
|
109
|
+
* the current pointer offset.
|
|
110
|
+
* If the buffer's memory is insufficient, this method will create a new
|
|
111
|
+
* buffer (a copy) with a length that is twice (byteLength + current offset).
|
|
112
|
+
* @param byteLength
|
|
113
|
+
*/
|
|
114
|
+
ensureAvailable(byteLength?: number): this;
|
|
115
|
+
/**
|
|
116
|
+
* Read a byte and return false if the byte's value is 0, or true otherwise.
|
|
117
|
+
* Moves pointer forward by one byte.
|
|
118
|
+
*/
|
|
119
|
+
readBoolean(): boolean;
|
|
120
|
+
/**
|
|
121
|
+
* Read a signed 8-bit integer and move pointer forward by 1 byte.
|
|
122
|
+
*/
|
|
123
|
+
readInt8(): number;
|
|
124
|
+
/**
|
|
125
|
+
* Read an unsigned 8-bit integer and move pointer forward by 1 byte.
|
|
126
|
+
*/
|
|
127
|
+
readUint8(): number;
|
|
128
|
+
/**
|
|
129
|
+
* Alias for {@link IOBuffer#readUint8}.
|
|
130
|
+
*/
|
|
131
|
+
readByte(): number;
|
|
132
|
+
/**
|
|
133
|
+
* Read `n` bytes and move pointer forward by `n` bytes.
|
|
134
|
+
*/
|
|
135
|
+
readBytes(n?: number): Uint8Array;
|
|
136
|
+
/**
|
|
137
|
+
* Read a 16-bit signed integer and move pointer forward by 2 bytes.
|
|
138
|
+
*/
|
|
139
|
+
readInt16(): number;
|
|
140
|
+
/**
|
|
141
|
+
* Read a 16-bit unsigned integer and move pointer forward by 2 bytes.
|
|
142
|
+
*/
|
|
143
|
+
readUint16(): number;
|
|
144
|
+
/**
|
|
145
|
+
* Read a 32-bit signed integer and move pointer forward by 4 bytes.
|
|
146
|
+
*/
|
|
147
|
+
readInt32(): number;
|
|
148
|
+
/**
|
|
149
|
+
* Read a 32-bit unsigned integer and move pointer forward by 4 bytes.
|
|
150
|
+
*/
|
|
151
|
+
readUint32(): number;
|
|
152
|
+
/**
|
|
153
|
+
* Read a 32-bit floating number and move pointer forward by 4 bytes.
|
|
154
|
+
*/
|
|
155
|
+
readFloat32(): number;
|
|
156
|
+
/**
|
|
157
|
+
* Read a 64-bit floating number and move pointer forward by 8 bytes.
|
|
158
|
+
*/
|
|
159
|
+
readFloat64(): number;
|
|
160
|
+
/**
|
|
161
|
+
* Read a 1-byte ASCII character and move pointer forward by 1 byte.
|
|
162
|
+
*/
|
|
163
|
+
readChar(): string;
|
|
164
|
+
/**
|
|
165
|
+
* Read `n` 1-byte ASCII characters and move pointer forward by `n` bytes.
|
|
166
|
+
*/
|
|
167
|
+
readChars(n?: number): string;
|
|
168
|
+
/**
|
|
169
|
+
* Read the next `n` bytes, return a UTF-8 decoded string and move pointer
|
|
170
|
+
* forward by `n` bytes.
|
|
171
|
+
*/
|
|
172
|
+
readUtf8(n?: number): string;
|
|
173
|
+
/**
|
|
174
|
+
* Write 0xff if the passed value is truthy, 0x00 otherwise and move pointer
|
|
175
|
+
* forward by 1 byte.
|
|
176
|
+
*/
|
|
177
|
+
writeBoolean(value: unknown): this;
|
|
178
|
+
/**
|
|
179
|
+
* Write `value` as an 8-bit signed integer and move pointer forward by 1 byte.
|
|
180
|
+
*/
|
|
181
|
+
writeInt8(value: number): this;
|
|
182
|
+
/**
|
|
183
|
+
* Write `value` as an 8-bit unsigned integer and move pointer forward by 1
|
|
184
|
+
* byte.
|
|
185
|
+
*/
|
|
186
|
+
writeUint8(value: number): this;
|
|
187
|
+
/**
|
|
188
|
+
* An alias for {@link IOBuffer#writeUint8}.
|
|
189
|
+
*/
|
|
190
|
+
writeByte(value: number): this;
|
|
191
|
+
/**
|
|
192
|
+
* Write all elements of `bytes` as uint8 values and move pointer forward by
|
|
193
|
+
* `bytes.length` bytes.
|
|
194
|
+
*/
|
|
195
|
+
writeBytes(bytes: ArrayLike<number>): this;
|
|
196
|
+
/**
|
|
197
|
+
* Write `value` as a 16-bit signed integer and move pointer forward by 2
|
|
198
|
+
* bytes.
|
|
199
|
+
*/
|
|
200
|
+
writeInt16(value: number): this;
|
|
201
|
+
/**
|
|
202
|
+
* Write `value` as a 16-bit unsigned integer and move pointer forward by 2
|
|
203
|
+
* bytes.
|
|
204
|
+
*/
|
|
205
|
+
writeUint16(value: number): this;
|
|
206
|
+
/**
|
|
207
|
+
* Write `value` as a 32-bit signed integer and move pointer forward by 4
|
|
208
|
+
* bytes.
|
|
209
|
+
*/
|
|
210
|
+
writeInt32(value: number): this;
|
|
211
|
+
/**
|
|
212
|
+
* Write `value` as a 32-bit unsigned integer and move pointer forward by 4
|
|
213
|
+
* bytes.
|
|
214
|
+
*/
|
|
215
|
+
writeUint32(value: number): this;
|
|
216
|
+
/**
|
|
217
|
+
* Write `value` as a 32-bit floating number and move pointer forward by 4
|
|
218
|
+
* bytes.
|
|
219
|
+
*/
|
|
220
|
+
writeFloat32(value: number): this;
|
|
221
|
+
/**
|
|
222
|
+
* Write `value` as a 64-bit floating number and move pointer forward by 8
|
|
223
|
+
* bytes.
|
|
224
|
+
*/
|
|
225
|
+
writeFloat64(value: number): this;
|
|
226
|
+
/**
|
|
227
|
+
* Write the charCode of `str`'s first character as an 8-bit unsigned integer
|
|
228
|
+
* and move pointer forward by 1 byte.
|
|
229
|
+
*/
|
|
230
|
+
writeChar(str: string): this;
|
|
231
|
+
/**
|
|
232
|
+
* Write the charCodes of all `str`'s characters as 8-bit unsigned integers
|
|
233
|
+
* and move pointer forward by `str.length` bytes.
|
|
234
|
+
*/
|
|
235
|
+
writeChars(str: string): this;
|
|
236
|
+
/**
|
|
237
|
+
* UTF-8 encode and write `str` to the current pointer offset and move pointer
|
|
238
|
+
* forward according to the encoded length.
|
|
239
|
+
*/
|
|
240
|
+
writeUtf8(str: string): this;
|
|
241
|
+
/**
|
|
242
|
+
* Export a Uint8Array view of the internal buffer.
|
|
243
|
+
* The view starts at the byte offset and its length
|
|
244
|
+
* is calculated to stop at the last written byte or the original length.
|
|
245
|
+
*/
|
|
246
|
+
toArray(): Uint8Array;
|
|
247
|
+
/**
|
|
248
|
+
* Update the last written byte offset
|
|
249
|
+
* @private
|
|
250
|
+
*/
|
|
251
|
+
private _updateLastWrittenByte;
|
|
252
|
+
}
|
|
253
|
+
export {};
|
|
254
|
+
//# sourceMappingURL=iobuffer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"iobuffer.d.ts","sourceRoot":"","sources":["../../src/iobuffer/iobuffer.ts"],"names":[],"mappings":";AAEA,KAAK,SAAS,GAAG,MAAM,GAAG,eAAe,GAAG,eAAe,GAAG,QAAQ,GAAG,MAAM,CAAC;AAEhF,UAAU,eAAe;IACvB;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,qBAAa,QAAQ;IACnB;;OAEG;IACI,MAAM,EAAE,eAAe,CAAC;IAE/B;;OAEG;IACI,UAAU,EAAE,MAAM,CAAC;IAE1B;;OAEG;IACI,UAAU,EAAE,MAAM,CAAC;IAE1B;;OAEG;IACI,MAAM,EAAE,MAAM,CAAC;IAEtB;;OAEG;IACI,MAAM,EAAE,MAAM,CAAC;IAEtB,OAAO,CAAC,eAAe,CAAS;IAChC,OAAO,CAAC,YAAY,CAAU;IAE9B,OAAO,CAAC,KAAK,CAAW;IACxB,OAAO,CAAC,KAAK,CAAS;IACtB,OAAO,CAAC,MAAM,CAAW;IAEzB,OAAO,C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