@graphty/graph-io 0.3.40 → 0.3.41
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/chunks/{choose-CS3fvGT1.js → choose-CwFQamH9.js} +2 -2
- package/dist/chunks/{choose-CS3fvGT1.js.map → choose-CwFQamH9.js.map} +1 -1
- package/dist/chunks/{constants-DqKZT6cH.js → constants-Cf4Nn6tw.js} +2 -2
- package/dist/chunks/{constants-DqKZT6cH.js.map → constants-Cf4Nn6tw.js.map} +1 -1
- package/dist/chunks/{escape-BJRLd3vJ.js → escape-DBb8zuNE.js} +2 -2
- package/dist/chunks/{escape-BJRLd3vJ.js.map → escape-DBb8zuNE.js.map} +1 -1
- package/dist/chunks/{export-B-aVCwyG.js → export-DD3Lvw-F.js} +173 -116
- package/dist/chunks/export-DD3Lvw-F.js.map +1 -0
- package/dist/chunks/{exporter-Bcp-l4Bo.js → exporter-BqtmlxNr.js} +545 -459
- package/dist/chunks/exporter-BqtmlxNr.js.map +1 -0
- package/dist/chunks/{exporter-6ocL_9x_.js → exporter-CS35R6Fg.js} +4 -4
- package/dist/chunks/{exporter-6ocL_9x_.js.map → exporter-CS35R6Fg.js.map} +1 -1
- package/dist/chunks/{exporter-BVXnV9-9.js → exporter-D8r1N2dU.js} +28 -16
- package/dist/chunks/exporter-D8r1N2dU.js.map +1 -0
- package/dist/chunks/{exporter-SFYkDzD0.js → exporter-NMplSnYn.js} +23 -20
- package/dist/chunks/{exporter-SFYkDzD0.js.map → exporter-NMplSnYn.js.map} +1 -1
- package/dist/chunks/{importer-CPqnIY8m.js → importer-BKC7AmCA.js} +42 -29
- package/dist/chunks/importer-BKC7AmCA.js.map +1 -0
- package/dist/chunks/{importer-D_srHyj6.js → importer-BdWHmlmG.js} +4 -4
- package/dist/chunks/{importer-D_srHyj6.js.map → importer-BdWHmlmG.js.map} +1 -1
- package/dist/chunks/{importer-AjwOJrn2.js → importer-BfbzWk6k.js} +202 -181
- package/dist/chunks/importer-BfbzWk6k.js.map +1 -0
- package/dist/chunks/{importer-BpuS3J8C.js → importer-BmaZcskq.js} +73 -60
- package/dist/chunks/importer-BmaZcskq.js.map +1 -0
- package/dist/chunks/{importer-DEp_fYjf.js → importer-DviEsHy4.js} +92 -64
- package/dist/chunks/importer-DviEsHy4.js.map +1 -0
- package/dist/chunks/{importer-DcKB97kW.js → importer-S-abxJHn.js} +5 -5
- package/dist/chunks/{importer-DcKB97kW.js.map → importer-S-abxJHn.js.map} +1 -1
- package/dist/chunks/{importer-BJlGAOht.js → importer-r29cWnEf.js} +3 -3
- package/dist/chunks/{importer-BJlGAOht.js.map → importer-r29cWnEf.js.map} +1 -1
- package/dist/chunks/{json-elements-DpO6AXIc.js → json-elements-DdF-etPT.js} +3 -3
- package/dist/chunks/{json-elements-DpO6AXIc.js.map → json-elements-DdF-etPT.js.map} +1 -1
- package/dist/chunks/{ontology-export-50L9DOV4.js → ontology-export-BC0zyPhj.js} +2 -2
- package/dist/chunks/{ontology-export-50L9DOV4.js.map → ontology-export-BC0zyPhj.js.map} +1 -1
- package/dist/chunks/{records-r3SFHz11.js → records-Uc3LkABx.js} +15 -12
- package/dist/chunks/records-Uc3LkABx.js.map +1 -0
- package/dist/chunks/{text-Bjfa1xYL.js → text-Bh9SaAob.js} +20 -11
- package/dist/chunks/text-Bh9SaAob.js.map +1 -0
- package/dist/csv.js +67 -49
- package/dist/csv.js.map +1 -1
- package/dist/cx.js +1 -1
- package/dist/cx2.js +2 -2
- package/dist/cys.js +1 -1
- package/dist/dot.js +1 -1
- package/dist/gexf.js +195 -97
- package/dist/gexf.js.map +1 -1
- package/dist/gml.js +170 -149
- package/dist/gml.js.map +1 -1
- package/dist/graph-io.js +26 -26
- package/dist/graphml.js +2 -2
- package/dist/json.js +1 -1
- package/dist/neo4j.js +103 -65
- package/dist/neo4j.js.map +1 -1
- package/dist/obo.js +1 -1
- package/dist/pajek.js +1 -1
- package/dist/src/common/attributes.d.ts.map +1 -1
- package/dist/src/common/attributes.js +34 -9
- package/dist/src/common/attributes.js.map +1 -1
- package/dist/src/common/input.d.ts.map +1 -1
- package/dist/src/common/input.js +180 -102
- package/dist/src/common/input.js.map +1 -1
- package/dist/src/common/text.d.ts +7 -0
- package/dist/src/common/text.d.ts.map +1 -1
- package/dist/src/common/text.js +15 -7
- package/dist/src/common/text.js.map +1 -1
- package/dist/src/common/zip.d.ts.map +1 -1
- package/dist/src/common/zip.js +36 -19
- package/dist/src/common/zip.js.map +1 -1
- package/dist/src/formats/csv/exporter.d.ts.map +1 -1
- package/dist/src/formats/csv/exporter.js +77 -25
- package/dist/src/formats/csv/exporter.js.map +1 -1
- package/dist/src/formats/csv/importer.d.ts.map +1 -1
- package/dist/src/formats/csv/importer.js +16 -6
- package/dist/src/formats/csv/importer.js.map +1 -1
- package/dist/src/formats/csv/records.d.ts.map +1 -1
- package/dist/src/formats/csv/records.js +18 -10
- package/dist/src/formats/csv/records.js.map +1 -1
- package/dist/src/formats/cys/tables.d.ts.map +1 -1
- package/dist/src/formats/cys/tables.js +11 -8
- package/dist/src/formats/cys/tables.js.map +1 -1
- package/dist/src/formats/gexf/exporter.d.ts.map +1 -1
- package/dist/src/formats/gexf/exporter.js +65 -37
- package/dist/src/formats/gexf/exporter.js.map +1 -1
- package/dist/src/formats/gexf/importer.d.ts.map +1 -1
- package/dist/src/formats/gexf/importer.js +138 -50
- package/dist/src/formats/gexf/importer.js.map +1 -1
- package/dist/src/formats/gml/exporter.d.ts.map +1 -1
- package/dist/src/formats/gml/exporter.js +51 -35
- package/dist/src/formats/gml/exporter.js.map +1 -1
- package/dist/src/formats/gml/importer.d.ts.map +1 -1
- package/dist/src/formats/gml/importer.js +103 -58
- package/dist/src/formats/gml/importer.js.map +1 -1
- package/dist/src/formats/gml/syntax.d.ts.map +1 -1
- package/dist/src/formats/gml/syntax.js +17 -8
- package/dist/src/formats/gml/syntax.js.map +1 -1
- package/dist/src/formats/graphml/exporter.d.ts.map +1 -1
- package/dist/src/formats/graphml/exporter.js +34 -24
- package/dist/src/formats/graphml/exporter.js.map +1 -1
- package/dist/src/formats/graphml/importer.d.ts.map +1 -1
- package/dist/src/formats/graphml/importer.js +17 -13
- package/dist/src/formats/graphml/importer.js.map +1 -1
- package/dist/src/formats/graphml/tree.js +23 -14
- package/dist/src/formats/graphml/tree.js.map +1 -1
- package/dist/src/formats/graphml/yfiles.d.ts.map +1 -1
- package/dist/src/formats/graphml/yfiles.js +22 -10
- package/dist/src/formats/graphml/yfiles.js.map +1 -1
- package/dist/src/formats/json/exporter.d.ts.map +1 -1
- package/dist/src/formats/json/exporter.js +38 -21
- package/dist/src/formats/json/exporter.js.map +1 -1
- package/dist/src/formats/json/importer.d.ts.map +1 -1
- package/dist/src/formats/json/importer.js +536 -343
- package/dist/src/formats/json/importer.js.map +1 -1
- package/dist/src/formats/json/obographs.js +29 -17
- package/dist/src/formats/json/obographs.js.map +1 -1
- package/dist/src/formats/neo4j/exporter.d.ts.map +1 -1
- package/dist/src/formats/neo4j/exporter.js +73 -43
- package/dist/src/formats/neo4j/exporter.js.map +1 -1
- package/dist/src/formats/neo4j/header.d.ts.map +1 -1
- package/dist/src/formats/neo4j/header.js +37 -16
- package/dist/src/formats/neo4j/header.js.map +1 -1
- package/dist/src/formats/neo4j/importer.d.ts.map +1 -1
- package/dist/src/formats/neo4j/importer.js +21 -11
- package/dist/src/formats/neo4j/importer.js.map +1 -1
- package/dist/src/formats/obo/exporter.d.ts.map +1 -1
- package/dist/src/formats/obo/exporter.js +18 -7
- package/dist/src/formats/obo/exporter.js.map +1 -1
- package/dist/src/formats/pajek/exporter.d.ts.map +1 -1
- package/dist/src/formats/pajek/exporter.js +142 -73
- package/dist/src/formats/pajek/exporter.js.map +1 -1
- package/dist/src/formats/pajek/importer.d.ts.map +1 -1
- package/dist/src/formats/pajek/importer.js +26 -15
- package/dist/src/formats/pajek/importer.js.map +1 -1
- package/dist/src/formats/pajek/syntax.d.ts.map +1 -1
- package/dist/src/formats/pajek/syntax.js +85 -58
- package/dist/src/formats/pajek/syntax.js.map +1 -1
- package/dist/src/formats/xgmml/emit.d.ts +7 -0
- package/dist/src/formats/xgmml/emit.d.ts.map +1 -1
- package/dist/src/formats/xgmml/emit.js +79 -40
- package/dist/src/formats/xgmml/emit.js.map +1 -1
- package/dist/src/formats/xgmml/exporter.d.ts.map +1 -1
- package/dist/src/formats/xgmml/exporter.js +38 -12
- package/dist/src/formats/xgmml/exporter.js.map +1 -1
- package/dist/src/formats/xgmml/importer.d.ts.map +1 -1
- package/dist/src/formats/xgmml/importer.js +38 -18
- package/dist/src/formats/xgmml/importer.js.map +1 -1
- package/dist/src/sniff.js +109 -57
- package/dist/src/sniff.js.map +1 -1
- package/dist/xgmml.js +2 -2
- package/package.json +2 -2
- package/src/common/attributes.ts +59 -19
- package/src/common/input.ts +216 -102
- package/src/common/text.ts +24 -15
- package/src/common/zip.ts +47 -18
- package/src/formats/csv/exporter.ts +103 -39
- package/src/formats/csv/importer.ts +17 -6
- package/src/formats/csv/records.ts +19 -10
- package/src/formats/cys/tables.ts +11 -10
- package/src/formats/gexf/exporter.ts +67 -36
- package/src/formats/gexf/importer.ts +173 -63
- package/src/formats/gml/exporter.ts +78 -82
- package/src/formats/gml/importer.ts +119 -68
- package/src/formats/gml/syntax.ts +18 -8
- package/src/formats/graphml/exporter.ts +44 -24
- package/src/formats/graphml/importer.ts +18 -11
- package/src/formats/graphml/tree.ts +22 -12
- package/src/formats/graphml/yfiles.ts +23 -10
- package/src/formats/json/exporter.ts +40 -21
- package/src/formats/json/importer.ts +701 -385
- package/src/formats/json/obographs.ts +35 -15
- package/src/formats/neo4j/exporter.ts +79 -41
- package/src/formats/neo4j/header.ts +50 -16
- package/src/formats/neo4j/importer.ts +21 -10
- package/src/formats/obo/exporter.ts +34 -17
- package/src/formats/pajek/exporter.ts +180 -117
- package/src/formats/pajek/importer.ts +27 -15
- package/src/formats/pajek/syntax.ts +99 -58
- package/src/formats/xgmml/emit.ts +88 -40
- package/src/formats/xgmml/exporter.ts +40 -12
- package/src/formats/xgmml/importer.ts +45 -23
- package/src/sniff.ts +115 -59
- package/dist/chunks/export-B-aVCwyG.js.map +0 -1
- package/dist/chunks/exporter-BVXnV9-9.js.map +0 -1
- package/dist/chunks/exporter-Bcp-l4Bo.js.map +0 -1
- package/dist/chunks/importer-AjwOJrn2.js.map +0 -1
- package/dist/chunks/importer-BpuS3J8C.js.map +0 -1
- package/dist/chunks/importer-CPqnIY8m.js.map +0 -1
- package/dist/chunks/importer-DEp_fYjf.js.map +0 -1
- package/dist/chunks/records-r3SFHz11.js.map +0 -1
- package/dist/chunks/text-Bjfa1xYL.js.map +0 -1
|
@@ -804,29 +804,12 @@ function declareResolved(sink, domain, decl, report, where) {
|
|
|
804
804
|
throw err;
|
|
805
805
|
}
|
|
806
806
|
if (err.code === "E_COLUMN_EXISTS" && !renamed) {
|
|
807
|
-
|
|
808
|
-
const id = current.origin?.id ?? null;
|
|
809
|
-
const name = uniqueColumnName(current.name, id, taken);
|
|
810
|
-
report.warning(
|
|
811
|
-
"coercion",
|
|
812
|
-
COLUMN_RENAMED_CODE,
|
|
813
|
-
`${domain} column "${current.name}" renamed to "${name}": the sink already holds that name with another shape`,
|
|
814
|
-
{ ...where, element: where?.element ?? current.name }
|
|
815
|
-
);
|
|
816
|
-
current = { ...current, name };
|
|
807
|
+
current = renameColumn(sink, domain, current, report, where);
|
|
817
808
|
renamed = true;
|
|
818
809
|
continue;
|
|
819
810
|
}
|
|
820
811
|
if (err.code === "E_DUPLICATE_ROLE" && current.role !== void 0 && !roleDropped) {
|
|
821
|
-
|
|
822
|
-
report.warning(
|
|
823
|
-
"coercion",
|
|
824
|
-
ROLE_TAKEN_CODE,
|
|
825
|
-
`${domain} column "${current.name}" loses the ${current.role} role: "${holder}" already holds it`,
|
|
826
|
-
{ ...where, element: where?.element ?? current.name }
|
|
827
|
-
);
|
|
828
|
-
const { role: _role, ...withoutRole } = current;
|
|
829
|
-
current = withoutRole;
|
|
812
|
+
current = dropRole(err, domain, current, current.role, report, where);
|
|
830
813
|
roleDropped = true;
|
|
831
814
|
continue;
|
|
832
815
|
}
|
|
@@ -834,6 +817,29 @@ function declareResolved(sink, domain, decl, report, where) {
|
|
|
834
817
|
}
|
|
835
818
|
}
|
|
836
819
|
}
|
|
820
|
+
function renameColumn(sink, domain, decl, report, where) {
|
|
821
|
+
const taken = takenIn(sink, domain);
|
|
822
|
+
const id = decl.origin?.id ?? null;
|
|
823
|
+
const name = uniqueColumnName(decl.name, id, taken);
|
|
824
|
+
report.warning(
|
|
825
|
+
"coercion",
|
|
826
|
+
COLUMN_RENAMED_CODE,
|
|
827
|
+
`${domain} column "${decl.name}" renamed to "${name}": the sink already holds that name with another shape`,
|
|
828
|
+
{ ...where, element: where?.element ?? decl.name }
|
|
829
|
+
);
|
|
830
|
+
return { ...decl, name };
|
|
831
|
+
}
|
|
832
|
+
function dropRole(err, domain, decl, role, report, where) {
|
|
833
|
+
const holder = typeof err.details.holder === "string" ? err.details.holder : "another column";
|
|
834
|
+
report.warning(
|
|
835
|
+
"coercion",
|
|
836
|
+
ROLE_TAKEN_CODE,
|
|
837
|
+
`${domain} column "${decl.name}" loses the ${role} role: "${holder}" already holds it`,
|
|
838
|
+
{ ...where, element: where?.element ?? decl.name }
|
|
839
|
+
);
|
|
840
|
+
const { role: _role, ...withoutRole } = decl;
|
|
841
|
+
return withoutRole;
|
|
842
|
+
}
|
|
837
843
|
function declareCompanion(sink, domain, companion, report) {
|
|
838
844
|
try {
|
|
839
845
|
return declareOn(sink, domain, companion);
|
|
@@ -2300,124 +2306,175 @@ function reportTextEncoding(report, encoding) {
|
|
|
2300
2306
|
async function* textChunks(rawInput, report, options = {}) {
|
|
2301
2307
|
const input = normalizeInput(rawInput);
|
|
2302
2308
|
const signal = options.signal ?? null;
|
|
2303
|
-
const onProgress = options.onProgress ?? null;
|
|
2304
2309
|
const filter = new TextFilter(report, options);
|
|
2305
2310
|
throwIfAborted(signal);
|
|
2306
2311
|
if (typeof input === "string") {
|
|
2307
2312
|
reportTextEncoding(report, options.encoding);
|
|
2308
|
-
|
|
2309
|
-
let done2 = 0;
|
|
2310
|
-
let start = 0;
|
|
2311
|
-
while (start < input.length) {
|
|
2312
|
-
throwIfAborted(signal);
|
|
2313
|
-
let end = Math.min(start + DECODE_SLICE, input.length);
|
|
2314
|
-
const highSurrogate = (input.charCodeAt(end - 1) & 64512) === 55296;
|
|
2315
|
-
if (end < input.length && highSurrogate) {
|
|
2316
|
-
end++;
|
|
2317
|
-
}
|
|
2318
|
-
const piece = start === 0 && end === input.length ? input : input.slice(start, end);
|
|
2319
|
-
start = end;
|
|
2320
|
-
const text = filter.push(piece);
|
|
2321
|
-
if (text.length > 0) {
|
|
2322
|
-
yield text;
|
|
2323
|
-
}
|
|
2324
|
-
if (onProgress !== null) {
|
|
2325
|
-
done2 += utf8Length(piece);
|
|
2326
|
-
onProgress(done2, total);
|
|
2327
|
-
}
|
|
2328
|
-
}
|
|
2329
|
-
if (input.length === 0) {
|
|
2330
|
-
onProgress?.(0, 0);
|
|
2331
|
-
}
|
|
2332
|
-
filter.end();
|
|
2313
|
+
yield* stringTextChunks(input, filter, options);
|
|
2333
2314
|
return;
|
|
2334
2315
|
}
|
|
2335
2316
|
const decoder = new ByteDecoder(report, options);
|
|
2336
|
-
const headBytes = Math.max(options.declarationBytes ?? HEAD_BYTES, BOM_BYTES);
|
|
2337
2317
|
if (input instanceof Uint8Array) {
|
|
2338
|
-
|
|
2339
|
-
decoder.start(input.subarray(0, headBytes));
|
|
2340
|
-
for (let offset = 0; offset < length; offset += DECODE_SLICE) {
|
|
2341
|
-
throwIfAborted(signal);
|
|
2342
|
-
if (input.byteLength !== length) {
|
|
2343
|
-
throw new GraphFormatError(
|
|
2344
|
-
"E_UNSUPPORTED",
|
|
2345
|
-
"the input's buffer was detached (transferred) or resized during the import",
|
|
2346
|
-
{ reason: "detached" }
|
|
2347
|
-
);
|
|
2348
|
-
}
|
|
2349
|
-
const slice = input.subarray(offset, Math.min(offset + DECODE_SLICE, length));
|
|
2350
|
-
const text = filter.push(decoder.decode(slice, offset + DECODE_SLICE < length));
|
|
2351
|
-
if (text.length > 0) {
|
|
2352
|
-
yield text;
|
|
2353
|
-
}
|
|
2354
|
-
onProgress?.(Math.min(offset + DECODE_SLICE, length), length);
|
|
2355
|
-
}
|
|
2356
|
-
if (length === 0) {
|
|
2357
|
-
onProgress?.(0, 0);
|
|
2358
|
-
}
|
|
2359
|
-
filter.end();
|
|
2318
|
+
yield* byteTextChunks(input, filter, decoder, options);
|
|
2360
2319
|
return;
|
|
2361
2320
|
}
|
|
2362
|
-
const
|
|
2321
|
+
const stream = new StreamText(filter, decoder, options);
|
|
2322
|
+
for await (const chunk of isReadableStream(input) ? streamChunks(input, signal) : input) {
|
|
2323
|
+
throwIfAborted(signal);
|
|
2324
|
+
const text = stream.push(chunk);
|
|
2325
|
+
if (text.length > 0) {
|
|
2326
|
+
yield text;
|
|
2327
|
+
}
|
|
2328
|
+
options.onProgress?.(stream.done);
|
|
2329
|
+
}
|
|
2330
|
+
const tail = stream.end();
|
|
2331
|
+
if (tail.length > 0) {
|
|
2332
|
+
yield tail;
|
|
2333
|
+
}
|
|
2334
|
+
filter.end();
|
|
2335
|
+
options.onProgress?.(stream.done, stream.done);
|
|
2336
|
+
}
|
|
2337
|
+
function stringSliceEnd(input, start) {
|
|
2338
|
+
const end = Math.min(start + DECODE_SLICE, input.length);
|
|
2339
|
+
const highSurrogate = (input.charCodeAt(end - 1) & 64512) === 55296;
|
|
2340
|
+
return end < input.length && highSurrogate ? end + 1 : end;
|
|
2341
|
+
}
|
|
2342
|
+
function* stringTextChunks(input, filter, options) {
|
|
2343
|
+
const signal = options.signal ?? null;
|
|
2344
|
+
const onProgress = options.onProgress ?? null;
|
|
2345
|
+
const total = onProgress === null ? 0 : utf8Length(input);
|
|
2363
2346
|
let done = 0;
|
|
2364
|
-
let
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
const
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2347
|
+
let start = 0;
|
|
2348
|
+
while (start < input.length) {
|
|
2349
|
+
throwIfAborted(signal);
|
|
2350
|
+
const end = stringSliceEnd(input, start);
|
|
2351
|
+
const piece = start === 0 && end === input.length ? input : input.slice(start, end);
|
|
2352
|
+
start = end;
|
|
2353
|
+
const text = filter.push(piece);
|
|
2354
|
+
if (text.length > 0) {
|
|
2355
|
+
yield text;
|
|
2356
|
+
}
|
|
2357
|
+
if (onProgress !== null) {
|
|
2358
|
+
done += utf8Length(piece);
|
|
2359
|
+
onProgress(done, total);
|
|
2360
|
+
}
|
|
2361
|
+
}
|
|
2362
|
+
if (input.length === 0) {
|
|
2363
|
+
onProgress?.(0, 0);
|
|
2364
|
+
}
|
|
2365
|
+
filter.end();
|
|
2366
|
+
}
|
|
2367
|
+
function* byteTextChunks(input, filter, decoder, options) {
|
|
2368
|
+
const signal = options.signal ?? null;
|
|
2369
|
+
const length = input.byteLength;
|
|
2370
|
+
decoder.start(input.subarray(0, headByteCount(options)));
|
|
2371
|
+
for (let offset = 0; offset < length; offset += DECODE_SLICE) {
|
|
2375
2372
|
throwIfAborted(signal);
|
|
2376
|
-
|
|
2377
|
-
|
|
2373
|
+
if (input.byteLength !== length) {
|
|
2374
|
+
throw new GraphFormatError(
|
|
2375
|
+
"E_UNSUPPORTED",
|
|
2376
|
+
"the input's buffer was detached (transferred) or resized during the import",
|
|
2377
|
+
{ reason: "detached" }
|
|
2378
|
+
);
|
|
2379
|
+
}
|
|
2380
|
+
const slice = input.subarray(offset, Math.min(offset + DECODE_SLICE, length));
|
|
2381
|
+
const text = filter.push(decoder.decode(slice, offset + DECODE_SLICE < length));
|
|
2382
|
+
if (text.length > 0) {
|
|
2383
|
+
yield text;
|
|
2384
|
+
}
|
|
2385
|
+
options.onProgress?.(Math.min(offset + DECODE_SLICE, length), length);
|
|
2386
|
+
}
|
|
2387
|
+
if (length === 0) {
|
|
2388
|
+
options.onProgress?.(0, 0);
|
|
2389
|
+
}
|
|
2390
|
+
filter.end();
|
|
2391
|
+
}
|
|
2392
|
+
function headByteCount(options) {
|
|
2393
|
+
return Math.max(options.declarationBytes ?? HEAD_BYTES, BOM_BYTES);
|
|
2394
|
+
}
|
|
2395
|
+
class StreamText {
|
|
2396
|
+
/**
|
|
2397
|
+
* Create the reader of one stream input.
|
|
2398
|
+
* @param filter - the text checks
|
|
2399
|
+
* @param decoder - the byte decoder
|
|
2400
|
+
* @param options - progress, the declaration reader and its size
|
|
2401
|
+
*/
|
|
2402
|
+
constructor(filter, decoder, options) {
|
|
2403
|
+
this.filter = filter;
|
|
2404
|
+
this.decoder = decoder;
|
|
2405
|
+
this.done = 0;
|
|
2406
|
+
this.head = [];
|
|
2407
|
+
this.headLength = 0;
|
|
2408
|
+
this.headBytes = headByteCount(options);
|
|
2409
|
+
this.needed = options.declaredEncoding === void 0 ? BOM_BYTES : this.headBytes;
|
|
2410
|
+
this.counting = (options.onProgress ?? null) !== null;
|
|
2411
|
+
}
|
|
2412
|
+
/**
|
|
2413
|
+
* Read the next chunk.
|
|
2414
|
+
* @param chunk - a string or a Uint8Array (anything else is E_UNSUPPORTED)
|
|
2415
|
+
* @returns its filtered text; empty while bytes are held back
|
|
2416
|
+
*/
|
|
2417
|
+
push(chunk) {
|
|
2378
2418
|
if (typeof chunk === "string") {
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
} else {
|
|
2385
|
-
decoder.start(new Uint8Array(0));
|
|
2386
|
-
}
|
|
2387
|
-
text = filter.push(pending + chunk);
|
|
2388
|
-
done += onProgress === null ? 0 : utf8Length(chunk);
|
|
2389
|
-
} else if (bytes !== null) {
|
|
2390
|
-
done += bytes.byteLength;
|
|
2391
|
-
if (decoder.started) {
|
|
2392
|
-
text = filter.push(decoder.decode(bytes, true));
|
|
2393
|
-
} else {
|
|
2394
|
-
head.push(bytes);
|
|
2395
|
-
headLength += bytes.byteLength;
|
|
2396
|
-
text = headLength >= needed ? filter.push(flushHead(true)) : "";
|
|
2397
|
-
}
|
|
2398
|
-
} else {
|
|
2419
|
+
this.done += this.counting ? utf8Length(chunk) : 0;
|
|
2420
|
+
return this.filter.push(this.beforeText() + chunk);
|
|
2421
|
+
}
|
|
2422
|
+
const bytes = asBytes(chunk);
|
|
2423
|
+
if (bytes === null) {
|
|
2399
2424
|
throw new GraphFormatError("E_UNSUPPORTED", "an input chunk must be a string or a Uint8Array", {
|
|
2400
2425
|
reason: "chunk type",
|
|
2401
2426
|
found: typeof chunk
|
|
2402
2427
|
});
|
|
2403
2428
|
}
|
|
2404
|
-
|
|
2405
|
-
|
|
2429
|
+
this.done += bytes.byteLength;
|
|
2430
|
+
if (this.decoder.started) {
|
|
2431
|
+
return this.filter.push(this.decoder.decode(bytes, true));
|
|
2432
|
+
}
|
|
2433
|
+
this.head.push(bytes);
|
|
2434
|
+
this.headLength += bytes.byteLength;
|
|
2435
|
+
return this.headLength >= this.needed ? this.filter.push(this.flushHead(true)) : "";
|
|
2436
|
+
}
|
|
2437
|
+
/**
|
|
2438
|
+
* The input ended: the filtered text of whatever is still held or pending.
|
|
2439
|
+
* @returns the text
|
|
2440
|
+
*/
|
|
2441
|
+
end() {
|
|
2442
|
+
let tail = "";
|
|
2443
|
+
if (this.headLength > 0) {
|
|
2444
|
+
tail = this.flushHead(false);
|
|
2445
|
+
} else if (this.decoder.started) {
|
|
2446
|
+
tail = this.decoder.decode(new Uint8Array(0), false);
|
|
2406
2447
|
}
|
|
2407
|
-
|
|
2448
|
+
return this.filter.push(tail);
|
|
2408
2449
|
}
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2450
|
+
/**
|
|
2451
|
+
* Start the decoder on the held bytes and decode them.
|
|
2452
|
+
* @param stream - whether more bytes follow
|
|
2453
|
+
* @returns their text
|
|
2454
|
+
*/
|
|
2455
|
+
flushHead(stream) {
|
|
2456
|
+
const bytes = concatBytes(this.head);
|
|
2457
|
+
this.head = [];
|
|
2458
|
+
this.headLength = 0;
|
|
2459
|
+
this.decoder.start(bytes.subarray(0, this.headBytes));
|
|
2460
|
+
return this.decoder.decode(bytes, stream);
|
|
2414
2461
|
}
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
|
|
2462
|
+
/**
|
|
2463
|
+
* A text chunk follows: finish any byte sequence still pending in the decoder before switching
|
|
2464
|
+
* to text. The BOM and declaration checks apply to the start of the input only, so bytes after
|
|
2465
|
+
* text are never taken for a BOM.
|
|
2466
|
+
* @returns the text of the pending bytes
|
|
2467
|
+
*/
|
|
2468
|
+
beforeText() {
|
|
2469
|
+
if (this.headLength > 0) {
|
|
2470
|
+
return this.decoder.flushBeforeText(() => this.flushHead(false));
|
|
2471
|
+
}
|
|
2472
|
+
if (this.decoder.started) {
|
|
2473
|
+
return this.decoder.flushBeforeText(() => this.decoder.decode(new Uint8Array(0), false));
|
|
2474
|
+
}
|
|
2475
|
+
this.decoder.start(new Uint8Array(0));
|
|
2476
|
+
return "";
|
|
2418
2477
|
}
|
|
2419
|
-
filter.end();
|
|
2420
|
-
onProgress?.(done, done);
|
|
2421
2478
|
}
|
|
2422
2479
|
function isReadableStream(input) {
|
|
2423
2480
|
return typeof input.getReader === "function";
|
|
@@ -4368,4 +4425,4 @@ export {
|
|
|
4368
4425
|
INVALID_ENCODING_CODE as y,
|
|
4369
4426
|
INVALID_UTF8_CODE as z
|
|
4370
4427
|
};
|
|
4371
|
-
//# sourceMappingURL=export-
|
|
4428
|
+
//# sourceMappingURL=export-DD3Lvw-F.js.map
|