spliterator 6.0.1 → 6.2.0
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/README.md +70 -0
- package/out/index.d.ts +26 -23
- package/out/index.d.ts.map +1 -1
- package/out/index.js +26 -23
- package/out/index.js.map +1 -1
- package/out/lib/AsyncSpliterator.d.ts.map +1 -1
- package/out/lib/AsyncSpliterator.js +28 -0
- package/out/lib/AsyncSpliterator.js.map +1 -1
- package/out/lib/CSVSpliterator.d.ts +8 -18
- package/out/lib/CSVSpliterator.d.ts.map +1 -1
- package/out/lib/CSVSpliterator.js +4 -47
- package/out/lib/CSVSpliterator.js.map +1 -1
- package/out/lib/CharacterSequence.d.ts +16 -1
- package/out/lib/CharacterSequence.d.ts.map +1 -1
- package/out/lib/CharacterSequence.js +37 -0
- package/out/lib/CharacterSequence.js.map +1 -1
- package/out/lib/XLSXSpliterator.d.ts +143 -0
- package/out/lib/XLSXSpliterator.d.ts.map +1 -0
- package/out/lib/XLSXSpliterator.js +161 -0
- package/out/lib/XLSXSpliterator.js.map +1 -0
- package/out/lib/core/AsyncSpliterator.d.ts +227 -0
- package/out/lib/core/AsyncSpliterator.d.ts.map +1 -0
- package/out/lib/core/AsyncSpliterator.js +510 -0
- package/out/lib/core/AsyncSpliterator.js.map +1 -0
- package/out/lib/core/BufferController.d.ts +77 -0
- package/out/lib/core/BufferController.d.ts.map +1 -0
- package/out/lib/core/BufferController.js +118 -0
- package/out/lib/core/BufferController.js.map +1 -0
- package/out/lib/core/CharacterSequence.d.ts +72 -0
- package/out/lib/core/CharacterSequence.d.ts.map +1 -0
- package/out/lib/core/CharacterSequence.js +347 -0
- package/out/lib/core/CharacterSequence.js.map +1 -0
- package/out/lib/core/CompositeDataView.d.ts +111 -0
- package/out/lib/core/CompositeDataView.d.ts.map +1 -0
- package/out/lib/core/CompositeDataView.js +241 -0
- package/out/lib/core/CompositeDataView.js.map +1 -0
- package/out/lib/core/IndexQueue.d.ts +48 -0
- package/out/lib/core/IndexQueue.d.ts.map +1 -0
- package/out/lib/core/IndexQueue.js +111 -0
- package/out/lib/core/IndexQueue.js.map +1 -0
- package/out/lib/core/SlidingWindow.d.ts +47 -0
- package/out/lib/core/SlidingWindow.d.ts.map +1 -0
- package/out/lib/core/SlidingWindow.js +63 -0
- package/out/lib/core/SlidingWindow.js.map +1 -0
- package/out/lib/core/Spliterator.d.ts +96 -0
- package/out/lib/core/Spliterator.d.ts.map +1 -0
- package/out/lib/core/Spliterator.js +330 -0
- package/out/lib/core/Spliterator.js.map +1 -0
- package/out/lib/core/wasm_base64.d.ts +19 -0
- package/out/lib/core/wasm_base64.d.ts.map +1 -0
- package/out/lib/core/wasm_base64.js +19 -0
- package/out/lib/core/wasm_base64.js.map +1 -0
- package/out/lib/core/wasm_module.d.ts +57 -0
- package/out/lib/core/wasm_module.d.ts.map +1 -0
- package/out/lib/core/wasm_module.js +34 -0
- package/out/lib/core/wasm_module.js.map +1 -0
- package/out/lib/formats/CSVSpliterator.d.ts +131 -0
- package/out/lib/formats/CSVSpliterator.d.ts.map +1 -0
- package/out/lib/formats/CSVSpliterator.js +172 -0
- package/out/lib/formats/CSVSpliterator.js.map +1 -0
- package/out/lib/formats/JSONSpliterator.d.ts +44 -0
- package/out/lib/formats/JSONSpliterator.d.ts.map +1 -0
- package/out/lib/formats/JSONSpliterator.js +77 -0
- package/out/lib/formats/JSONSpliterator.js.map +1 -0
- package/out/lib/formats/PSVSpliterator.d.ts +21 -0
- package/out/lib/formats/PSVSpliterator.d.ts.map +1 -0
- package/out/lib/formats/PSVSpliterator.js +22 -0
- package/out/lib/formats/PSVSpliterator.js.map +1 -0
- package/out/lib/formats/TSVSpliterator.d.ts +21 -0
- package/out/lib/formats/TSVSpliterator.d.ts.map +1 -0
- package/out/lib/formats/TSVSpliterator.js +22 -0
- package/out/lib/formats/TSVSpliterator.js.map +1 -0
- package/out/lib/formats/TextSpliterator.d.ts +53 -0
- package/out/lib/formats/TextSpliterator.d.ts.map +1 -0
- package/out/lib/formats/TextSpliterator.js +67 -0
- package/out/lib/formats/TextSpliterator.js.map +1 -0
- package/out/lib/formats/XLSXSpliterator.d.ts +143 -0
- package/out/lib/formats/XLSXSpliterator.d.ts.map +1 -0
- package/out/lib/formats/XLSXSpliterator.js +161 -0
- package/out/lib/formats/XLSXSpliterator.js.map +1 -0
- package/out/lib/formats/casing.d.ts +27 -0
- package/out/lib/formats/casing.d.ts.map +1 -0
- package/out/lib/formats/casing.js +68 -0
- package/out/lib/formats/casing.js.map +1 -0
- package/out/lib/formats/row-emitters.d.ts +35 -0
- package/out/lib/formats/row-emitters.d.ts.map +1 -0
- package/out/lib/formats/row-emitters.js +50 -0
- package/out/lib/formats/row-emitters.js.map +1 -0
- package/out/lib/internal/shared.d.ts +155 -0
- package/out/lib/internal/shared.d.ts.map +1 -0
- package/out/lib/internal/shared.js +41 -0
- package/out/lib/internal/shared.js.map +1 -0
- package/out/lib/internal/utils.d.ts +37 -0
- package/out/lib/internal/utils.d.ts.map +1 -0
- package/out/lib/internal/utils.js +39 -0
- package/out/lib/internal/utils.js.map +1 -0
- package/out/lib/io/adaptive-source.d.ts +39 -0
- package/out/lib/io/adaptive-source.d.ts.map +1 -0
- package/out/lib/io/adaptive-source.js +95 -0
- package/out/lib/io/adaptive-source.js.map +1 -0
- package/out/lib/io/writer.d.ts +45 -0
- package/out/lib/io/writer.d.ts.map +1 -0
- package/out/lib/io/writer.js +57 -0
- package/out/lib/io/writer.js.map +1 -0
- package/out/lib/iterators/AsyncSequence.d.ts +180 -0
- package/out/lib/iterators/AsyncSequence.d.ts.map +1 -0
- package/out/lib/iterators/AsyncSequence.js +432 -0
- package/out/lib/iterators/AsyncSequence.js.map +1 -0
- package/out/lib/iterators/chunks.d.ts +20 -0
- package/out/lib/iterators/chunks.d.ts.map +1 -0
- package/out/lib/iterators/chunks.js +36 -0
- package/out/lib/iterators/chunks.js.map +1 -0
- package/out/lib/iterators/pivot.d.ts +30 -0
- package/out/lib/iterators/pivot.d.ts.map +1 -0
- package/out/lib/iterators/pivot.js +47 -0
- package/out/lib/iterators/pivot.js.map +1 -0
- package/out/lib/iterators/zip.d.ts +33 -0
- package/out/lib/iterators/zip.d.ts.map +1 -0
- package/out/lib/iterators/zip.js +59 -0
- package/out/lib/iterators/zip.js.map +1 -0
- package/out/lib/parallel/merge-async-iterators.d.ts +12 -0
- package/out/lib/parallel/merge-async-iterators.d.ts.map +1 -0
- package/out/lib/parallel/merge-async-iterators.js +39 -0
- package/out/lib/parallel/merge-async-iterators.js.map +1 -0
- package/out/lib/parallel/parallel-map-runtime.d.ts +22 -0
- package/out/lib/parallel/parallel-map-runtime.d.ts.map +1 -0
- package/out/lib/parallel/parallel-map-runtime.js +60 -0
- package/out/lib/parallel/parallel-map-runtime.js.map +1 -0
- package/out/lib/parallel/parallel-map-worker-entry.d.ts +11 -0
- package/out/lib/parallel/parallel-map-worker-entry.d.ts.map +1 -0
- package/out/lib/parallel/parallel-map-worker-entry.js +41 -0
- package/out/lib/parallel/parallel-map-worker-entry.js.map +1 -0
- package/out/lib/parallel/parallel-map-workers.d.ts +57 -0
- package/out/lib/parallel/parallel-map-workers.d.ts.map +1 -0
- package/out/lib/parallel/parallel-map-workers.js +82 -0
- package/out/lib/parallel/parallel-map-workers.js.map +1 -0
- package/out/lib/parallel/parallel-map.d.ts +28 -0
- package/out/lib/parallel/parallel-map.d.ts.map +1 -0
- package/out/lib/parallel/parallel-map.js +30 -0
- package/out/lib/parallel/parallel-map.js.map +1 -0
- package/out/lib/parallel/segment-runtime.d.ts +27 -0
- package/out/lib/parallel/segment-runtime.d.ts.map +1 -0
- package/out/lib/parallel/segment-runtime.js +41 -0
- package/out/lib/parallel/segment-runtime.js.map +1 -0
- package/out/lib/parallel/segment-worker-entry.d.ts +10 -0
- package/out/lib/parallel/segment-worker-entry.d.ts.map +1 -0
- package/out/lib/parallel/segment-worker-entry.js +59 -0
- package/out/lib/parallel/segment-worker-entry.js.map +1 -0
- package/out/lib/parallel/segment-workers.d.ts +56 -0
- package/out/lib/parallel/segment-workers.d.ts.map +1 -0
- package/out/lib/parallel/segment-workers.js +110 -0
- package/out/lib/parallel/segment-workers.js.map +1 -0
- package/out/lib/parallel/segments.d.ts +31 -0
- package/out/lib/parallel/segments.d.ts.map +1 -0
- package/out/lib/parallel/segments.js +52 -0
- package/out/lib/parallel/segments.js.map +1 -0
- package/out/lib/row-emitters.d.ts +35 -0
- package/out/lib/row-emitters.d.ts.map +1 -0
- package/out/lib/row-emitters.js +50 -0
- package/out/lib/row-emitters.js.map +1 -0
- package/out/lib/wasm_base64.d.ts +4 -1
- package/out/lib/wasm_base64.d.ts.map +1 -1
- package/out/lib/wasm_base64.js +4 -1
- package/out/lib/wasm_base64.js.map +1 -1
- package/out/lib/wasm_module.d.ts +15 -0
- package/out/lib/wasm_module.d.ts.map +1 -1
- package/out/lib/wasm_module.js +2 -1
- package/out/lib/wasm_module.js.map +1 -1
- package/out/node/cli/commands/csv.d.ts +113 -0
- package/out/node/cli/commands/csv.d.ts.map +1 -1
- package/out/node/cli/commands/csv.js +34 -36
- package/out/node/cli/commands/csv.js.map +1 -1
- package/out/node/cli/commands/iterate.d.ts +92 -0
- package/out/node/cli/commands/iterate.d.ts.map +1 -1
- package/out/node/cli/commands/iterate.js +26 -28
- package/out/node/cli/commands/iterate.js.map +1 -1
- package/out/node/cli/commands/parallel.d.ts +102 -0
- package/out/node/cli/commands/parallel.d.ts.map +1 -0
- package/out/node/cli/commands/parallel.js +426 -0
- package/out/node/cli/commands/parallel.js.map +1 -0
- package/out/node/cli/index.js +5 -0
- package/out/node/cli/index.js.map +1 -1
- package/out/node/cli/spec.d.ts +51 -0
- package/out/node/cli/spec.d.ts.map +1 -0
- package/out/node/cli/spec.js +78 -0
- package/out/node/cli/spec.js.map +1 -0
- package/out/node/cli/utils.d.ts +36 -18
- package/out/node/cli/utils.d.ts.map +1 -1
- package/out/node/cli/utils.js +48 -39
- package/out/node/cli/utils.js.map +1 -1
- package/out/node/fs/index.d.ts +1 -1
- package/out/node/fs/index.d.ts.map +1 -1
- package/out/node/fs/index.js +1 -1
- package/out/node/fs/index.js.map +1 -1
- package/package.json +18 -8
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license MIT
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*/
|
|
6
|
+
import type { Stats } from "node:fs";
|
|
7
|
+
import type { FileHandle } from "node:fs/promises";
|
|
8
|
+
import type { PathBuilderLike } from "path-ts";
|
|
9
|
+
/**
|
|
10
|
+
* A trimmed-down version of the Node.js `Stats` interface.
|
|
11
|
+
*/
|
|
12
|
+
export type StatsLike = Pick<Stats, "size" | "blksize" | "mtimeMs">;
|
|
13
|
+
/**
|
|
14
|
+
* A trimmed-down version of the Node.js `FileHandle` interface.
|
|
15
|
+
*/
|
|
16
|
+
export type FileHandleLike = Pick<FileHandle, "fd" | "stat" | "close" | "read" | "readableWebStream" | "createReadStream">;
|
|
17
|
+
/**
|
|
18
|
+
* A tuple representing a window of bytes in a buffer.
|
|
19
|
+
*/
|
|
20
|
+
export type ByteRange = [
|
|
21
|
+
/**
|
|
22
|
+
* The starting byte index of the window.
|
|
23
|
+
*/
|
|
24
|
+
start: number,
|
|
25
|
+
/**
|
|
26
|
+
* The ending byte index of the window.
|
|
27
|
+
*/
|
|
28
|
+
end: number
|
|
29
|
+
];
|
|
30
|
+
/**
|
|
31
|
+
* Typed arrays that may be used as sources for byte streams.
|
|
32
|
+
*/
|
|
33
|
+
export type TypedArray = Uint8Array | Uint8ClampedArray | Uint16Array | Uint32Array | Int8Array | Int16Array | Int32Array | BigUint64Array | BigInt64Array | Float32Array | Float64Array;
|
|
34
|
+
/**
|
|
35
|
+
* A source of bytes that can be read from.
|
|
36
|
+
*/
|
|
37
|
+
export type ReadableSource = FileHandleLike | TypedArray;
|
|
38
|
+
/**
|
|
39
|
+
* Type-predicate to determine if a value is a file handle.
|
|
40
|
+
*/
|
|
41
|
+
export declare function isFileHandleLike(input: unknown): input is FileHandleLike;
|
|
42
|
+
/**
|
|
43
|
+
* Type-helper to determine the destination type for a typed array.
|
|
44
|
+
*
|
|
45
|
+
* This is useful to infer the ultimate return type of a function which optionally accepts a typed array destination.
|
|
46
|
+
*/
|
|
47
|
+
export type TypedArrayFallback<T> = T extends TypedArray ? T : Uint8Array;
|
|
48
|
+
/**
|
|
49
|
+
* Options for reading a range of bytes from a source.
|
|
50
|
+
*/
|
|
51
|
+
export interface ReadBytesOptions {
|
|
52
|
+
/**
|
|
53
|
+
* The offset from where to begin writing to the buffer.
|
|
54
|
+
*
|
|
55
|
+
* This is useful when reading multiple buffers into a single buffer.
|
|
56
|
+
*
|
|
57
|
+
* @default 0
|
|
58
|
+
*/
|
|
59
|
+
offset?: number;
|
|
60
|
+
/**
|
|
61
|
+
* How many bytes to read.
|
|
62
|
+
*
|
|
63
|
+
* @default `length of buffer`
|
|
64
|
+
*/
|
|
65
|
+
length?: number;
|
|
66
|
+
/**
|
|
67
|
+
* From where to start reading.
|
|
68
|
+
*/
|
|
69
|
+
position?: number;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* A trait for reading a range of bytes from a source.
|
|
73
|
+
*
|
|
74
|
+
* While possible with a variety of platform-specific APIs, this trait provides a common interface for reading byte
|
|
75
|
+
* ranges.
|
|
76
|
+
*/
|
|
77
|
+
export interface ByteRangeReader extends AsyncIterator<Uint8Array> {
|
|
78
|
+
/**
|
|
79
|
+
* Reads a range of bytes from a source.
|
|
80
|
+
*/
|
|
81
|
+
read(options?: ReadBytesOptions): Promise<Uint8Array>;
|
|
82
|
+
read<B extends TypedArray>(options: ReadBytesOptions & {
|
|
83
|
+
buffer: B;
|
|
84
|
+
}): Promise<B>;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* An isomorphic file resource which can be read from and disposed.
|
|
88
|
+
*
|
|
89
|
+
* Generally, this interface aligns with the `File` interface in the browser.
|
|
90
|
+
*/
|
|
91
|
+
export interface FileResourceLike extends File {
|
|
92
|
+
/**
|
|
93
|
+
* Slice the file into a new file resource.
|
|
94
|
+
*
|
|
95
|
+
* @param start - The byte offset to start the slice.
|
|
96
|
+
* @param end - The byte offset to end the slice.
|
|
97
|
+
*/
|
|
98
|
+
slice(start: number, end: number): FileResourceLike;
|
|
99
|
+
/**
|
|
100
|
+
* The block size of the file, if known.
|
|
101
|
+
*/
|
|
102
|
+
blockSize?: number;
|
|
103
|
+
[Symbol.asyncDispose]?(): PromiseLike<void>;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Type-predicate to determine if a value is a file resource.
|
|
107
|
+
*/
|
|
108
|
+
export declare function isFileResourceLike(input: unknown): input is FileResourceLike;
|
|
109
|
+
/**
|
|
110
|
+
* Given a file resource, adds a `read` method to read a range of bytes.
|
|
111
|
+
*
|
|
112
|
+
* This allows the web `File` interface to be used as a byte range reader.
|
|
113
|
+
*/
|
|
114
|
+
export declare function applyReaderPolyfill<T extends FileResourceLike>(file: T): asserts file is T & ByteRangeReader;
|
|
115
|
+
/**
|
|
116
|
+
* An asynchronous iterable byte stream.
|
|
117
|
+
*
|
|
118
|
+
* String chunks are tolerated and UTF-8 encoded on arrival — a `fs.createReadStream(path, "utf8")` or Node `Readable`
|
|
119
|
+
* in string mode would otherwise coerce to garbage bytes via `TypedArray.set`.
|
|
120
|
+
*
|
|
121
|
+
* Note that as an iterable this will drained of all bytes when iterated over.
|
|
122
|
+
*/
|
|
123
|
+
export interface AsyncChunkIterator extends AsyncIterable<Uint8Array | string> {
|
|
124
|
+
/**
|
|
125
|
+
* Disposes of the byte stream, releasing any resources.
|
|
126
|
+
*
|
|
127
|
+
* This method is optional and may not be implemented by all byte streams.
|
|
128
|
+
*/
|
|
129
|
+
[Symbol.asyncDispose]?(): PromiseLike<void>;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* An asynchronous resource to a delimited byte stream, which can be a...
|
|
133
|
+
*
|
|
134
|
+
* - `string` representing a file path.
|
|
135
|
+
* - {@linkcode URL} object representing a file path.
|
|
136
|
+
* - {@linkcode FileHandleLike} object representing an open file handle.
|
|
137
|
+
* - {@linkcode AsyncChunkIterator} object representing an asynchronous byte stream — anything async-iterable over bytes
|
|
138
|
+
* qualifies: a Node `Readable` (child-process stdout, a gunzip pipe), a web `ReadableStream` wrapped via
|
|
139
|
+
* `Symbol.asyncIterator`, or a hand-rolled generator.
|
|
140
|
+
*/
|
|
141
|
+
export type AsyncDataResource = string | URL | FileHandleLike | AsyncChunkIterator | PathBuilderLike;
|
|
142
|
+
/**
|
|
143
|
+
* A resource to a delimited byte stream, i.e., a file buffer, handle, or path.
|
|
144
|
+
*
|
|
145
|
+
* @see {@link AsyncDataResource} : File paths, URLs, and handles.
|
|
146
|
+
* @see {@link TypedArray} : Buffers and typed arrays.
|
|
147
|
+
*/
|
|
148
|
+
export type DataResource = AsyncDataResource | TypedArray;
|
|
149
|
+
/**
|
|
150
|
+
* A trimmed-down version of the text decoder interface.
|
|
151
|
+
*/
|
|
152
|
+
export interface TextDecoderLike {
|
|
153
|
+
decode(input: Uint8Array): string;
|
|
154
|
+
}
|
|
155
|
+
//# sourceMappingURL=shared.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../../lib/internal/shared.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAEpC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAElD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAE9C;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS,CAAC,CAAA;AAEnE;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,IAAI,CAChC,UAAU,EACV,IA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K,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,gBAAgB,CAAA;IAEnD;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAElB,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,IAAI,WAAW,CAAC,IAAI,CAAC,CAAA;CAC3C;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,gBAAgB,CAE5E;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,SAAS,gBAAgB,EAAE,IAAI,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,IAAI,CAAC,GAAG,eAAe,CAsB5G;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,kBAAmB,SAAQ,aAAa,CAAC,UAAU,GAAG,MAAM,CAAC;IAC7E;;;;OAIG;IACH,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,IAAI,WAAW,CAAC,IAAI,CAAC,CAAA;CAC3C;AAED;;;;;;;;;GASG;AACH,MAAM,MAAM,iBAAiB,GAAG,MAAM,GAAG,GAAG,GAAG,cAAc,GAAG,kBAAkB,GAAG,eAAe,CAAA;AAEpG;;;;;GAKG;AACH,MAAM,MAAM,YAAY,GAAG,iBAAiB,GAAG,UAAU,CAAA;AAEzD;;GAEG;AACH,MAAM,WAAW,eAAe;IAC/B,MAAM,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAAA;CACjC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license MIT
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Type-predicate to determine if a value is a file handle.
|
|
8
|
+
*/
|
|
9
|
+
export function isFileHandleLike(input) {
|
|
10
|
+
return Boolean(input && typeof input === "object" && "fd" in input);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Type-predicate to determine if a value is a file resource.
|
|
14
|
+
*/
|
|
15
|
+
export function isFileResourceLike(input) {
|
|
16
|
+
return Boolean(input && typeof input === "object" && "slice" in input);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Given a file resource, adds a `read` method to read a range of bytes.
|
|
20
|
+
*
|
|
21
|
+
* This allows the web `File` interface to be used as a byte range reader.
|
|
22
|
+
*/
|
|
23
|
+
export function applyReaderPolyfill(file) {
|
|
24
|
+
if ("read" in file && typeof file.read === "function") {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
Object.assign(file, {
|
|
28
|
+
async read(options = {}) {
|
|
29
|
+
const { position: start = 0, length = file.size, offset = 0 } = options;
|
|
30
|
+
const windowed = file.slice(start, start + length);
|
|
31
|
+
const bytes = (await windowed.bytes());
|
|
32
|
+
if (options.buffer) {
|
|
33
|
+
const destination = options.buffer;
|
|
34
|
+
destination.set(bytes, offset);
|
|
35
|
+
return destination;
|
|
36
|
+
}
|
|
37
|
+
return bytes;
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=shared.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared.js","sourceRoot":"","sources":["../../../lib/internal/shared.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAyDH;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,KAAc;IAC9C,OAAO,OAAO,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,IAAI,IAAI,KAAK,CAAC,CAAA;AACpE,CAAC;AAuED;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAAC,KAAc;IAChD,OAAO,OAAO,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,IAAI,KAAK,CAAC,CAAA;AACvE,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CAA6B,IAAO;IACtE,IAAI,MAAM,IAAI,IAAI,IAAI,OAAO,IAAI,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;QACvD,OAAM;IACP,CAAC;IAED,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE;QACnB,KAAK,CAAC,IAAI,CAAuB,OAAO,GAAsC,EAAE;YAC/E,MAAM,EAAE,QAAQ,EAAE,KAAK,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,CAAC,EAAE,GAAG,OAAO,CAAA;YACvE,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,CAAC,CAAA;YAElD,MAAM,KAAK,GAAG,CAAC,MAAM,QAAQ,CAAC,KAAK,EAAE,CAA0B,CAAA;YAE/D,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;gBACpB,MAAM,WAAW,GAAG,OAAO,CAAC,MAA+B,CAAA;gBAC3D,WAAW,CAAC,GAAG,CAAC,KAAY,EAAE,MAAM,CAAC,CAAA;gBAErC,OAAO,WAAW,CAAA;YACnB,CAAC;YAED,OAAO,KAAK,CAAA;QACb,CAAC;KACD,CAAC,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license MIT
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Convenience function to await an async iterable.
|
|
8
|
+
*/
|
|
9
|
+
export declare function iterateInParallel<T>(asyncIterable: AsyncIterable<T>): Promise<void>;
|
|
10
|
+
/**
|
|
11
|
+
* Type-predicate for checking if a value is iterable.
|
|
12
|
+
*
|
|
13
|
+
* @category Type Guard
|
|
14
|
+
* @category Object
|
|
15
|
+
*/
|
|
16
|
+
export declare function isIterable<T>(input: unknown): input is Iterable<T>;
|
|
17
|
+
/**
|
|
18
|
+
* Iterable that can be checked for the existence of a member.
|
|
19
|
+
*/
|
|
20
|
+
export interface IndexedIterable<T = unknown> extends Iterable<T> {
|
|
21
|
+
has(value: T): boolean;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Type-predicate for checking if an member within an iterable can be checked for existence.
|
|
25
|
+
*/
|
|
26
|
+
export declare function isIndexedIterable<T>(value: Iterable<T>): value is IndexedIterable<T>;
|
|
27
|
+
/**
|
|
28
|
+
* Extracts the property keys of an object that are of type `number`.
|
|
29
|
+
*/
|
|
30
|
+
export type NumericProperties<T> = {
|
|
31
|
+
[K in keyof T]: T[K] extends number ? K : never;
|
|
32
|
+
}[keyof T];
|
|
33
|
+
/**
|
|
34
|
+
* Given an iterable of objects, returns the sum of the specified property.
|
|
35
|
+
*/
|
|
36
|
+
export declare function sumOf<T extends object>(iterable: Iterable<T>, prop: NumericProperties<T>): number;
|
|
37
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../lib/internal/utils.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;GAEG;AACH,wBAAsB,iBAAiB,CAAC,CAAC,EAAE,aAAa,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAIzF;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,QAAQ,CAAC,CAAC,CAAC,CAElE;AAED;;GAEG;AACH,MAAM,WAAW,eAAe,CAAC,CAAC,GAAG,OAAO,CAAE,SAAQ,QAAQ,CAAC,CAAC,CAAC;IAChE,GAAG,CAAC,KAAK,EAAE,CAAC,GAAG,OAAO,CAAA;CACtB;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,KAAK,IAAI,eAAe,CAAC,CAAC,CAAC,CAEpF;AAED;;GAEG;AACH,MAAM,MAAM,iBAAiB,CAAC,CAAC,IAAI;KACjC,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,MAAM,GAAG,CAAC,GAAG,KAAK;CAC/C,CAAC,MAAM,CAAC,CAAC,CAAA;AAEV;;GAEG;AACH,wBAAgB,KAAK,CAAC,CAAC,SAAS,MAAM,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAAG,MAAM,CAQjG"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license MIT
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Convenience function to await an async iterable.
|
|
8
|
+
*/
|
|
9
|
+
export async function iterateInParallel(asyncIterable) {
|
|
10
|
+
for await (const _ of asyncIterable) {
|
|
11
|
+
/* empty */
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Type-predicate for checking if a value is iterable.
|
|
16
|
+
*
|
|
17
|
+
* @category Type Guard
|
|
18
|
+
* @category Object
|
|
19
|
+
*/
|
|
20
|
+
export function isIterable(input) {
|
|
21
|
+
return Symbol.iterator in new Object(input);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Type-predicate for checking if an member within an iterable can be checked for existence.
|
|
25
|
+
*/
|
|
26
|
+
export function isIndexedIterable(value) {
|
|
27
|
+
return value && typeof value.has === "function";
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Given an iterable of objects, returns the sum of the specified property.
|
|
31
|
+
*/
|
|
32
|
+
export function sumOf(iterable, prop) {
|
|
33
|
+
let total = 0;
|
|
34
|
+
for (const item of iterable) {
|
|
35
|
+
total += item[prop];
|
|
36
|
+
}
|
|
37
|
+
return total;
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../lib/internal/utils.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAI,aAA+B;IACzE,IAAI,KAAK,EAAE,MAAM,CAAC,IAAI,aAAa,EAAE,CAAC;QACrC,WAAW;IACZ,CAAC;AACF,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,UAAU,CAAI,KAAc;IAC3C,OAAO,MAAM,CAAC,QAAQ,IAAI,IAAI,MAAM,CAAC,KAAK,CAAC,CAAA;AAC5C,CAAC;AASD;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAAI,KAAkB;IACtD,OAAO,KAAK,IAAI,OAAQ,KAAyB,CAAC,GAAG,KAAK,UAAU,CAAA;AACrE,CAAC;AASD;;GAEG;AACH,MAAM,UAAU,KAAK,CAAmB,QAAqB,EAAE,IAA0B;IACxF,IAAI,KAAK,GAAG,CAAC,CAAA;IAEb,KAAK,MAAM,IAAI,IAAI,QAAQ,EAAE,CAAC;QAC7B,KAAK,IAAI,IAAI,CAAC,IAAI,CAAW,CAAA;IAC9B,CAAC;IAED,OAAO,KAAK,CAAA;AACb,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license MIT
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*/
|
|
6
|
+
import { type AsyncSpliteratorInit } from "../core/Spliterator.js";
|
|
7
|
+
import type { AsyncChunkIterator, AsyncDataResource } from "../internal/shared.js";
|
|
8
|
+
/**
|
|
9
|
+
* Byte length at or below which a source is read whole and parsed synchronously.
|
|
10
|
+
*
|
|
11
|
+
* What this buys is **fixed setup cost** — opening a handle and standing up a read stream, ~100µs — not throughput, so
|
|
12
|
+
* the win decays as the source grows and the threshold marks where it stops being measurable. End-to-end against the
|
|
13
|
+
* streaming path (Node 26, min of 200 runs, two independent sweeps): ~1.85× at 635B, ~1.45× at 6.5KB, ~1.4× at 125KiB.
|
|
14
|
+
* At 253KiB and above the two runs disagreed on which was faster, so there is nothing reliable left to win.
|
|
15
|
+
*
|
|
16
|
+
* Raising this does not recover the much larger gap a raw synchronous parse shows (~1.6× even at 1GiB); that gap is
|
|
17
|
+
* eaten by the per-row cost of the sequence itself, which both paths pay. It only trades resident memory — a 1GiB
|
|
18
|
+
* source costs ~105MB streamed against ~1121MB read whole — for a difference that no longer measures.
|
|
19
|
+
*/
|
|
20
|
+
export declare const DEFAULT_BULK_THRESHOLD: number;
|
|
21
|
+
export interface AdaptiveSourceInit extends AsyncSpliteratorInit {
|
|
22
|
+
/**
|
|
23
|
+
* Byte length at or below which the whole source is read into memory and parsed synchronously, trading resident
|
|
24
|
+
* memory for speed.
|
|
25
|
+
*
|
|
26
|
+
* Raising it buys nothing measurable and costs memory linearly — the advantage is gone by ~256KiB. Set `0` to always
|
|
27
|
+
* stream, which is what you want when a bounded footprint is the reason you reached for this library.
|
|
28
|
+
*
|
|
29
|
+
* @default 128 KiB ({@linkcode DEFAULT_BULK_THRESHOLD})
|
|
30
|
+
*/
|
|
31
|
+
bulkThreshold?: number;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Take the delimited rows of `source`, reading it whole when it is small enough to be worth the memory and streaming it
|
|
35
|
+
* otherwise. Returns a sync iterable in the first case and an async one in the second; both satisfy
|
|
36
|
+
* {@linkcode AsyncSequence}.
|
|
37
|
+
*/
|
|
38
|
+
export declare function openDelimitedRows(source: AsyncDataResource | AsyncChunkIterator, init?: AdaptiveSourceInit): Promise<AsyncIterable<Uint8Array> | Iterable<Uint8Array>>;
|
|
39
|
+
//# sourceMappingURL=adaptive-source.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adaptive-source.d.ts","sourceRoot":"","sources":["../../../lib/io/adaptive-source.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,KAAK,oBAAoB,EAAe,MAAM,wBAAwB,CAAA;AAC/E,OAAO,KAAK,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAA;AAElF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,sBAAsB,QAAa,CAAA;AAEhD,MAAM,WAAW,kBAAmB,SAAQ,oBAAoB;IAC/D;;;;;;;;OAQG;IACH,aAAa,CAAC,EAAE,MAAM,CAAA;CACtB;AAuBD;;;;GAIG;AACH,wBAAsB,iBAAiB,CACtC,MAAM,EAAE,iBAAiB,GAAG,kBAAkB,EAC9C,IAAI,GAAE,kBAAuB,GAC3B,OAAO,CAAC,aAAa,CAAC,UAAU,CAAC,GAAG,QAAQ,CAAC,UAAU,CAAC,CAAC,CAuB3D"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license MIT
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*/
|
|
6
|
+
import { CharacterSequence } from "../core/CharacterSequence.js";
|
|
7
|
+
import { Spliterator } from "../core/Spliterator.js";
|
|
8
|
+
/**
|
|
9
|
+
* Byte length at or below which a source is read whole and parsed synchronously.
|
|
10
|
+
*
|
|
11
|
+
* What this buys is **fixed setup cost** — opening a handle and standing up a read stream, ~100µs — not throughput, so
|
|
12
|
+
* the win decays as the source grows and the threshold marks where it stops being measurable. End-to-end against the
|
|
13
|
+
* streaming path (Node 26, min of 200 runs, two independent sweeps): ~1.85× at 635B, ~1.45× at 6.5KB, ~1.4× at 125KiB.
|
|
14
|
+
* At 253KiB and above the two runs disagreed on which was faster, so there is nothing reliable left to win.
|
|
15
|
+
*
|
|
16
|
+
* Raising this does not recover the much larger gap a raw synchronous parse shows (~1.6× even at 1GiB); that gap is
|
|
17
|
+
* eaten by the per-row cost of the sequence itself, which both paths pay. It only trades resident memory — a 1GiB
|
|
18
|
+
* source costs ~105MB streamed against ~1121MB read whole — for a difference that no longer measures.
|
|
19
|
+
*/
|
|
20
|
+
export const DEFAULT_BULK_THRESHOLD = 128 * 1024;
|
|
21
|
+
function isChunkIterator(source) {
|
|
22
|
+
return typeof source === "object" && source !== null && Symbol.asyncIterator in source;
|
|
23
|
+
}
|
|
24
|
+
function toBytes(chunk) {
|
|
25
|
+
return typeof chunk === "string" ? new TextEncoder().encode(chunk) : chunk;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Parse in-memory bytes with the synchronous engine.
|
|
29
|
+
*
|
|
30
|
+
* Awaiting {@linkcode CharacterSequence.whenReady} first is the point: the WASM scanner loads asynchronously, so a
|
|
31
|
+
* synchronous caller normally completes before it is available and silently uses the JS scanner. Reaching the sync
|
|
32
|
+
* engine through an async path is the one place that can be avoided — worth ~26% on a large source.
|
|
33
|
+
*/
|
|
34
|
+
async function bulk(bytes, init) {
|
|
35
|
+
await CharacterSequence.whenReady();
|
|
36
|
+
return Spliterator.fromSync(bytes, init);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Take the delimited rows of `source`, reading it whole when it is small enough to be worth the memory and streaming it
|
|
40
|
+
* otherwise. Returns a sync iterable in the first case and an async one in the second; both satisfy
|
|
41
|
+
* {@linkcode AsyncSequence}.
|
|
42
|
+
*/
|
|
43
|
+
export async function openDelimitedRows(source, init = {}) {
|
|
44
|
+
const threshold = init.bulkThreshold ?? DEFAULT_BULK_THRESHOLD;
|
|
45
|
+
if (threshold <= 0)
|
|
46
|
+
return Spliterator.fromAsync(source, init);
|
|
47
|
+
if (isChunkIterator(source))
|
|
48
|
+
return openChunkIterator(source, threshold, init);
|
|
49
|
+
let size;
|
|
50
|
+
try {
|
|
51
|
+
const { readFileSize } = await import("spliterator/node/fs");
|
|
52
|
+
size = await readFileSize(source);
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
// Unsized or unreachable by the Node adapter — the streaming path owns reporting why.
|
|
56
|
+
return Spliterator.fromAsync(source, init);
|
|
57
|
+
}
|
|
58
|
+
if (size > threshold)
|
|
59
|
+
return Spliterator.fromAsync(source, init);
|
|
60
|
+
const { readBytes } = await import("spliterator/node/fs");
|
|
61
|
+
return bulk(await readBytes(source, 0, size), init);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* A stream cannot be measured before it is read, so the size test becomes an end-of-input test: pull one chunk, and if
|
|
65
|
+
* the stream is already exhausted the whole input is in hand and no threshold policy is needed.
|
|
66
|
+
*
|
|
67
|
+
* When it is not exhausted the pulled chunks cannot be discarded, so the stream is re-headed with them in front.
|
|
68
|
+
*/
|
|
69
|
+
async function openChunkIterator(source, threshold, init) {
|
|
70
|
+
const iterator = source[Symbol.asyncIterator]();
|
|
71
|
+
const first = await iterator.next();
|
|
72
|
+
if (first.done)
|
|
73
|
+
return bulk(new Uint8Array(0), init);
|
|
74
|
+
const second = await iterator.next();
|
|
75
|
+
const head = toBytes(first.value);
|
|
76
|
+
if (second.done && head.byteLength <= threshold)
|
|
77
|
+
return bulk(head, init);
|
|
78
|
+
const pulled = second.done ? [first.value] : [first.value, second.value];
|
|
79
|
+
const reheaded = {
|
|
80
|
+
async *[Symbol.asyncIterator]() {
|
|
81
|
+
yield* pulled;
|
|
82
|
+
for (;;) {
|
|
83
|
+
const next = await iterator.next();
|
|
84
|
+
if (next.done)
|
|
85
|
+
return;
|
|
86
|
+
yield next.value;
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
if (Symbol.asyncDispose in source) {
|
|
91
|
+
reheaded[Symbol.asyncDispose] = () => source[Symbol.asyncDispose]();
|
|
92
|
+
}
|
|
93
|
+
return Spliterator.fromAsync(reheaded, init);
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=adaptive-source.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adaptive-source.js","sourceRoot":"","sources":["../../../lib/io/adaptive-source.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,O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a,CAAC;YAC5B,KAAK,CAAC,CAAC,MAAM,CAAA;YAEb,SAAS,CAAC;gBACT,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAA;gBAElC,IAAI,IAAI,CAAC,IAAI;oBAAE,OAAM;gBAErB,MAAM,IAAI,CAAC,KAAK,CAAA;YACjB,CAAC;QACF,CAAC;KACD,CAAA;IAED,IAAI,MAAM,CAAC,YAAY,IAAI,MAAM,EAAE,CAAC;QACnC,QAAQ,CAAC,MAAM,CAAC,YAAY,CAAC,GAAG,GAAG,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,YAAY,CAAE,EAAE,CAAA;IACrE,CAAC;IAED,OAAO,WAAW,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAA;AAC7C,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license MIT
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*/
|
|
6
|
+
import { type WriteStream, type PathLike } from "node:fs";
|
|
7
|
+
/**
|
|
8
|
+
* Callback for writing a line to a newline-delimited file.
|
|
9
|
+
*
|
|
10
|
+
* The trailing newline is appended for you — pass the content alone.
|
|
11
|
+
*/
|
|
12
|
+
export interface WriteLineCallback {
|
|
13
|
+
/**
|
|
14
|
+
* Write a line to the file, terminated with a newline. The content should not contain one itself.
|
|
15
|
+
*/
|
|
16
|
+
(content: string): Promise<void>;
|
|
17
|
+
/**
|
|
18
|
+
* Write a chunk to the file, terminated with a newline. The chunk should not contain one itself.
|
|
19
|
+
*/
|
|
20
|
+
(chunk: any, encoding: BufferEncoding): Promise<void>;
|
|
21
|
+
}
|
|
22
|
+
export interface NewlineWriter extends AsyncDisposable {
|
|
23
|
+
/**
|
|
24
|
+
* Write a line to the file, terminated with a newline.
|
|
25
|
+
*
|
|
26
|
+
* The content should not contain a newline character — the writer supplies the delimiter.
|
|
27
|
+
*/
|
|
28
|
+
write: WriteLineCallback;
|
|
29
|
+
dispose: () => Promise<void>;
|
|
30
|
+
writer: WriteStream;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Creates a writer for newline-delimited files.
|
|
34
|
+
*
|
|
35
|
+
* Every {@linkcode NewlineWriter.write} terminates its content with `\n`, so the file is delimited (and round-trips
|
|
36
|
+
* through {@linkcode TextSpliterator}) without the caller appending anything:
|
|
37
|
+
*
|
|
38
|
+
* ```ts
|
|
39
|
+
* await using out = createNewlineWriter("rows.jsonl")
|
|
40
|
+
*
|
|
41
|
+
* for (const row of rows) await out.write(JSON.stringify(row))
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export declare function createNewlineWriter(filePath: PathLike): NewlineWriter;
|
|
45
|
+
//# sourceMappingURL=writer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"writer.d.ts","sourceRoot":"","sources":["../../../lib/io/writer.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,KAAK,WAAW,EAAqB,KAAK,QAAQ,EAAE,MAAM,SAAS,CAAA;AAE5E;;;;GAIG;AACH,MAAM,WAAW,iBAAiB;IACjC;;OAEG;IACH,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAChC;;OAEG;IACH,CAAC,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CACrD;AAED,MAAM,WAAW,aAAc,SAAQ,eAAe;IACrD;;;;OAIG;IACH,KAAK,EAAE,iBAAiB,CAAA;IACxB,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;IAC5B,MAAM,EAAE,WAAW,CAAA;CACnB;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,QAAQ,GAAG,aAAa,CA6CrE"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license MIT
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*/
|
|
6
|
+
import { createWriteStream } from "node:fs";
|
|
7
|
+
/**
|
|
8
|
+
* Creates a writer for newline-delimited files.
|
|
9
|
+
*
|
|
10
|
+
* Every {@linkcode NewlineWriter.write} terminates its content with `\n`, so the file is delimited (and round-trips
|
|
11
|
+
* through {@linkcode TextSpliterator}) without the caller appending anything:
|
|
12
|
+
*
|
|
13
|
+
* ```ts
|
|
14
|
+
* await using out = createNewlineWriter("rows.jsonl")
|
|
15
|
+
*
|
|
16
|
+
* for (const row of rows) await out.write(JSON.stringify(row))
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export function createNewlineWriter(filePath) {
|
|
20
|
+
const writer = createWriteStream(filePath);
|
|
21
|
+
const write = (content, encoding) => {
|
|
22
|
+
return new Promise((resolve, reject) => {
|
|
23
|
+
const settle = (error) => {
|
|
24
|
+
if (error) {
|
|
25
|
+
reject(error);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
resolve();
|
|
29
|
+
};
|
|
30
|
+
// The delimiter goes out as its own chunk rather than concatenated onto `content`: the
|
|
31
|
+
// two-argument overload accepts a Buffer, and `buffer + "\n"` would stringify it via
|
|
32
|
+
// `toString()` and corrupt the bytes. Stream writes are ordered, so the newline always
|
|
33
|
+
// follows its content, and settling on the delimiter's callback resolves once the whole
|
|
34
|
+
// line has flushed.
|
|
35
|
+
writer.write(content, encoding ?? "utf8");
|
|
36
|
+
writer.write("\n", "utf8", settle);
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
const dispose = () => {
|
|
40
|
+
return new Promise((resolve, reject) => {
|
|
41
|
+
writer.close((error) => {
|
|
42
|
+
if (error) {
|
|
43
|
+
reject(error);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
resolve();
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
return {
|
|
51
|
+
write,
|
|
52
|
+
writer,
|
|
53
|
+
dispose,
|
|
54
|
+
[Symbol.asyncDispose]: dispose,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=writer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"writer.js","sourceRoot":"","sources":["../../../lib/io/writer.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAoB,iBAAiB,EAAiB,MAAM,SAAS,CAAA;AA6B5E;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,mBAAmB,CAAC,QAAkB;IACrD,MAAM,MAAM,GAAG,iBAAiB,CAAC,QAAQ,CAAC,CAAA;IAE1C,MAAM,KAAK,GAAsB,CAAC,OAAY,EAAE,QAAyB,EAAE,EAAE;QAC5E,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACtC,MAAM,MAAM,GAAG,CAAC,KAA+B,EAAQ,EAAE;gBACxD,IAAI,KAAK,EAAE,CAAC;oBACX,MAAM,CAAC,KAAK,CAAC,CAAA;oBAEb,OAAM;gBACP,CAAC;gBAED,OAAO,EAAE,CAAA;YACV,CAAC,CAAA;YAED,uFAAuF;YACvF,qFAAqF;YACrF,uFAAuF;YACvF,wFAAwF;YACxF,oBAAoB;YACpB,MAAM,CAAC,KAAK,CAAC,OAAO,EAAE,QAAQ,IAAI,MAAM,CAAC,CAAA;YACzC,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,CAAA;QACnC,CAAC,CAAC,CAAA;IACH,CAAC,CAAA;IAED,MAAM,OAAO,GAAG,GAAG,EAAE;QACpB,OAAO,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YAC5C,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;gBACtB,IAAI,KAAK,EAAE,CAAC;oBAC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