spliterator 1.5.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/LICENSE.md +650 -0
- package/README.md +119 -0
- package/out/index.d.ts +21 -0
- package/out/index.d.ts.map +1 -0
- package/out/index.js +21 -0
- package/out/index.js.map +1 -0
- package/out/lib/AsyncSpliterator.d.ts +127 -0
- package/out/lib/AsyncSpliterator.d.ts.map +1 -0
- package/out/lib/AsyncSpliterator.js +332 -0
- package/out/lib/AsyncSpliterator.js.map +1 -0
- package/out/lib/BufferController.d.ts +62 -0
- package/out/lib/BufferController.d.ts.map +1 -0
- package/out/lib/BufferController.js +93 -0
- package/out/lib/BufferController.js.map +1 -0
- package/out/lib/CSVSpliterator.d.ts +104 -0
- package/out/lib/CSVSpliterator.d.ts.map +1 -0
- package/out/lib/CSVSpliterator.js +83 -0
- package/out/lib/CSVSpliterator.js.map +1 -0
- package/out/lib/CharacterSequence.d.ts +103 -0
- package/out/lib/CharacterSequence.d.ts.map +1 -0
- package/out/lib/CharacterSequence.js +184 -0
- package/out/lib/CharacterSequence.js.map +1 -0
- package/out/lib/CompositeDataView.d.ts +104 -0
- package/out/lib/CompositeDataView.d.ts.map +1 -0
- package/out/lib/CompositeDataView.js +242 -0
- package/out/lib/CompositeDataView.js.map +1 -0
- package/out/lib/DelimitedChunkReader.d.ts +67 -0
- package/out/lib/DelimitedChunkReader.d.ts.map +1 -0
- package/out/lib/DelimitedChunkReader.js +113 -0
- package/out/lib/DelimitedChunkReader.js.map +1 -0
- package/out/lib/DelimiterTransformer.d.ts +27 -0
- package/out/lib/DelimiterTransformer.d.ts.map +1 -0
- package/out/lib/DelimiterTransformer.js +26 -0
- package/out/lib/DelimiterTransformer.js.map +1 -0
- package/out/lib/IndexQueue.d.ts +48 -0
- package/out/lib/IndexQueue.d.ts.map +1 -0
- package/out/lib/IndexQueue.js +80 -0
- package/out/lib/IndexQueue.js.map +1 -0
- package/out/lib/JSONSpliterator.d.ts +19 -0
- package/out/lib/JSONSpliterator.d.ts.map +1 -0
- package/out/lib/JSONSpliterator.js +55 -0
- package/out/lib/JSONSpliterator.js.map +1 -0
- package/out/lib/SlidingWindow.d.ts +93 -0
- package/out/lib/SlidingWindow.d.ts.map +1 -0
- package/out/lib/SlidingWindow.js +176 -0
- package/out/lib/SlidingWindow.js.map +1 -0
- package/out/lib/Spliterator.d.ts +51 -0
- package/out/lib/Spliterator.d.ts.map +1 -0
- package/out/lib/Spliterator.js +238 -0
- package/out/lib/Spliterator.js.map +1 -0
- package/out/lib/TextSpliterator.d.ts +40 -0
- package/out/lib/TextSpliterator.d.ts.map +1 -0
- package/out/lib/TextSpliterator.js +56 -0
- package/out/lib/TextSpliterator.js.map +1 -0
- package/out/lib/casing.d.ts +28 -0
- package/out/lib/casing.d.ts.map +1 -0
- package/out/lib/casing.js +69 -0
- package/out/lib/casing.js.map +1 -0
- package/out/lib/node/fs.d.ts +98 -0
- package/out/lib/node/fs.d.ts.map +1 -0
- package/out/lib/node/fs.js +162 -0
- package/out/lib/node/fs.js.map +1 -0
- package/out/lib/shared.d.ts +167 -0
- package/out/lib/shared.d.ts.map +1 -0
- package/out/lib/shared.js +92 -0
- package/out/lib/shared.js.map +1 -0
- package/out/lib/take.d.ts +26 -0
- package/out/lib/take.d.ts.map +1 -0
- package/out/lib/take.js +71 -0
- package/out/lib/take.js.map +1 -0
- package/out/lib/writer.d.ts +34 -0
- package/out/lib/writer.d.ts.map +1 -0
- package/out/lib/writer.js +41 -0
- package/out/lib/writer.js.map +1 -0
- package/package.json +100 -0
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*/
|
|
6
|
+
import { read } from "node:fs";
|
|
7
|
+
import { open } from "node:fs/promises";
|
|
8
|
+
import * as path from "node:path";
|
|
9
|
+
import { isFileHandleLike, } from "../shared.js";
|
|
10
|
+
/**
|
|
11
|
+
* An isomorphic file resource which can be read from and disposed.
|
|
12
|
+
*/
|
|
13
|
+
export class NodeFileResource {
|
|
14
|
+
#handle;
|
|
15
|
+
/**
|
|
16
|
+
* The last modified timestamp of the file.
|
|
17
|
+
*/
|
|
18
|
+
lastModified;
|
|
19
|
+
/**
|
|
20
|
+
* The name of the file.
|
|
21
|
+
*/
|
|
22
|
+
name;
|
|
23
|
+
/**
|
|
24
|
+
* @deprecated This property is not supported in Node.js.
|
|
25
|
+
*/
|
|
26
|
+
webkitRelativePath = "";
|
|
27
|
+
blockSize;
|
|
28
|
+
/**
|
|
29
|
+
* The byte length of the file.
|
|
30
|
+
*/
|
|
31
|
+
size;
|
|
32
|
+
/**
|
|
33
|
+
* The byte length of the file.
|
|
34
|
+
*
|
|
35
|
+
* Alias for {@linkcode #byteLength}.
|
|
36
|
+
*/
|
|
37
|
+
get byteLength() {
|
|
38
|
+
return this.size;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* The byte position of the file.
|
|
42
|
+
*/
|
|
43
|
+
#position;
|
|
44
|
+
type;
|
|
45
|
+
constructor(handle, init) {
|
|
46
|
+
this.#handle = handle;
|
|
47
|
+
this.lastModified = init.lastModified ?? Date.now();
|
|
48
|
+
this.name = init.name ?? "";
|
|
49
|
+
this.#position = init.position ?? 0;
|
|
50
|
+
this.size = (init.byteLength ?? 0) - this.#position;
|
|
51
|
+
this.blockSize = init.blockSize;
|
|
52
|
+
this.type = init.type ?? "";
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Read a range of bytes from the file.
|
|
56
|
+
*
|
|
57
|
+
* @param options - The options for reading the byte range.
|
|
58
|
+
*/
|
|
59
|
+
async read(options = {}) {
|
|
60
|
+
const byteLength = options.length ?? this.size;
|
|
61
|
+
const offset = options.offset ?? 0;
|
|
62
|
+
const buffer = (options.buffer ?? new Uint8Array(byteLength));
|
|
63
|
+
const position = options.position ?? this.#position;
|
|
64
|
+
await new Promise((resolve, reject) => read(this.#handle.fd, {
|
|
65
|
+
buffer,
|
|
66
|
+
offset,
|
|
67
|
+
position,
|
|
68
|
+
}, (error) => {
|
|
69
|
+
if (error)
|
|
70
|
+
reject(error);
|
|
71
|
+
else
|
|
72
|
+
resolve();
|
|
73
|
+
}));
|
|
74
|
+
return buffer;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Read the entire file as a byte array.
|
|
78
|
+
*
|
|
79
|
+
* @see {@linkcode slice} to create a sliced view of the file.
|
|
80
|
+
* @see {@linkcode arrayBuffer} to read the file as an array buffer.
|
|
81
|
+
*/
|
|
82
|
+
async bytes() {
|
|
83
|
+
return this.read();
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Read the entire file as an array buffer.
|
|
87
|
+
*
|
|
88
|
+
* @see {@linkcode slice} to create a sliced view of the file.
|
|
89
|
+
* @see {@linkcode bytes} to read the file as a byte array.
|
|
90
|
+
*/
|
|
91
|
+
arrayBuffer() {
|
|
92
|
+
return this.bytes().then((bytes) => bytes.buffer);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Slice the file into a new file resource.
|
|
96
|
+
*
|
|
97
|
+
* Note that the slice is a view of the original file, thus we're really just creating a new file
|
|
98
|
+
* resource with a different byte range.
|
|
99
|
+
*
|
|
100
|
+
* @param start - The starting byte offset.
|
|
101
|
+
* @param end - The ending byte offset.
|
|
102
|
+
* @param contentType - The content type of the slice.
|
|
103
|
+
*
|
|
104
|
+
* @returns A new file resource representing the sliced view of the file.
|
|
105
|
+
*/
|
|
106
|
+
slice(start, end, contentType) {
|
|
107
|
+
start = start ?? 0;
|
|
108
|
+
end = end ?? this.size;
|
|
109
|
+
const byteLength = Math.max(0, end - start);
|
|
110
|
+
return new NodeFileResource(this.#handle, {
|
|
111
|
+
name: this.name,
|
|
112
|
+
type: contentType ?? this.type,
|
|
113
|
+
position: this.#position + start,
|
|
114
|
+
byteLength,
|
|
115
|
+
lastModified: this.lastModified,
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Read the entire file as a string.
|
|
120
|
+
*/
|
|
121
|
+
async text() {
|
|
122
|
+
const buffer = await this.bytes();
|
|
123
|
+
const decoder = new TextDecoder();
|
|
124
|
+
return decoder.decode(buffer);
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Create a readable stream of the file.
|
|
128
|
+
*/
|
|
129
|
+
stream() {
|
|
130
|
+
return this.#handle.readableWebStream();
|
|
131
|
+
}
|
|
132
|
+
async [Symbol.asyncDispose]() {
|
|
133
|
+
return this.#handle.close();
|
|
134
|
+
}
|
|
135
|
+
dispose() {
|
|
136
|
+
return this.#handle.close();
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Create a new file resource from a file handle or path.
|
|
140
|
+
*/
|
|
141
|
+
static async open(input, stats, init = {}) {
|
|
142
|
+
let handle;
|
|
143
|
+
let name = "";
|
|
144
|
+
if (isFileHandleLike(input)) {
|
|
145
|
+
handle = input;
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
handle = await open(input, "r");
|
|
149
|
+
name = (init.name ?? typeof init.name === "string") ? init.name : path.basename(input.toString());
|
|
150
|
+
}
|
|
151
|
+
stats = stats ?? (await handle.stat());
|
|
152
|
+
return new NodeFileResource(handle, {
|
|
153
|
+
lastModified: stats.mtimeMs,
|
|
154
|
+
byteLength: stats.size,
|
|
155
|
+
...init,
|
|
156
|
+
name,
|
|
157
|
+
blockSize: stats.blksize,
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
export default NodeFileResource;
|
|
162
|
+
//# sourceMappingURL=fs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fs.js","sourceRoot":"","sources":["../../../lib/node/fs.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,IAAI,EAAmC,MAAM,SAAS,CAAA;AAC/D,OAAO,E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,UAAU,EAAE,KAAK,CAAC,IAAI;YACtB,GAAG,IAAI;YACP,IAAI;YACJ,SAAS,EAAE,KAAK,CAAC,OAAO;SACxB,CAAC,CAAA;IACH,CAAC;CACD;AAED,eAAe,gBAAgB,CAAA"}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*/
|
|
6
|
+
import { type Stats } from "node:fs";
|
|
7
|
+
import type { FileHandle } from "node:fs/promises";
|
|
8
|
+
/**
|
|
9
|
+
* A trimmed-down version of the Node.js `Stats` interface.
|
|
10
|
+
*/
|
|
11
|
+
export type StatsLike = Pick<Stats, "size" | "blksize" | "mtimeMs">;
|
|
12
|
+
/**
|
|
13
|
+
* A trimmed-down version of the Node.js `FileHandle` interface.
|
|
14
|
+
*/
|
|
15
|
+
export type FileHandleLike = Pick<FileHandle, "fd" | "stat" | "close" | "read" | "readableWebStream">;
|
|
16
|
+
/**
|
|
17
|
+
* A tuple representing a window of bytes in a buffer.
|
|
18
|
+
*/
|
|
19
|
+
export type ByteRange = [
|
|
20
|
+
/**
|
|
21
|
+
* The starting byte index of the window.
|
|
22
|
+
*/
|
|
23
|
+
start: number,
|
|
24
|
+
/**
|
|
25
|
+
* The ending byte index of the window.
|
|
26
|
+
*/
|
|
27
|
+
end: number
|
|
28
|
+
];
|
|
29
|
+
/**
|
|
30
|
+
* Typed arrays that may be used as sources for byte streams.
|
|
31
|
+
*/
|
|
32
|
+
export type TypedArray = Uint8Array | Uint8ClampedArray | Uint16Array | Uint32Array | Int8Array | Int16Array | Int32Array | BigUint64Array | BigInt64Array | Float32Array | Float64Array;
|
|
33
|
+
/**
|
|
34
|
+
* A source of bytes that can be read from.
|
|
35
|
+
*/
|
|
36
|
+
export type ReadableSource = FileHandleLike | TypedArray;
|
|
37
|
+
/**
|
|
38
|
+
* Type-predicate to determine if a value is a file handle.
|
|
39
|
+
*/
|
|
40
|
+
export declare function isFileHandleLike(input: unknown): input is FileHandleLike;
|
|
41
|
+
/**
|
|
42
|
+
* Type-helper to determine the destination type for a typed array.
|
|
43
|
+
*
|
|
44
|
+
* This is useful to infer the ultimate return type of a function which optionally accepts a typed
|
|
45
|
+
* 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
|
|
75
|
+
* for reading byte ranges.
|
|
76
|
+
*/
|
|
77
|
+
export interface ByteRangeReader {
|
|
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
|
+
* Read the entire file as a byte array.
|
|
94
|
+
*/
|
|
95
|
+
bytes(): Promise<Uint8Array>;
|
|
96
|
+
/**
|
|
97
|
+
* Slice the file into a new file resource.
|
|
98
|
+
*
|
|
99
|
+
* @param start - The byte offset to start the slice.
|
|
100
|
+
* @param end - The byte offset to end the slice.
|
|
101
|
+
*/
|
|
102
|
+
slice(start: number, end: number): FileResourceLike;
|
|
103
|
+
/**
|
|
104
|
+
* The block size of the file, if known.
|
|
105
|
+
*/
|
|
106
|
+
blockSize?: number;
|
|
107
|
+
[Symbol.asyncDispose]?(): PromiseLike<void>;
|
|
108
|
+
}
|
|
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
|
+
* Type-predicate to determine if a value is a file resource.
|
|
117
|
+
*/
|
|
118
|
+
export declare function isFileResourceLike(input: unknown): input is FileResourceLike;
|
|
119
|
+
/**
|
|
120
|
+
* An asynchronous resource to a delimited byte stream, which can be a...
|
|
121
|
+
*
|
|
122
|
+
* - `string` representing a file path.
|
|
123
|
+
* - `URL` object representing a file path.
|
|
124
|
+
* - `Buffer` containing the file contents.
|
|
125
|
+
* - `TypedArray` containing the file contents.
|
|
126
|
+
* - `FileHandleLike` object representing an open file handle.
|
|
127
|
+
*/
|
|
128
|
+
export type AsyncDataResource = string | URL | FileHandleLike | FileResourceLike;
|
|
129
|
+
/**
|
|
130
|
+
* A resource to a delimited byte stream, i.e., a file buffer, handle, or path.
|
|
131
|
+
*
|
|
132
|
+
* @see {@link AsyncDataResource} : File paths, URLs, and handles.
|
|
133
|
+
* @see {@link TypedArray} : Buffers and typed arrays.
|
|
134
|
+
*/
|
|
135
|
+
export type DataResource = AsyncDataResource | TypedArray;
|
|
136
|
+
/**
|
|
137
|
+
* A trimmed-down version of the text decoder interface.
|
|
138
|
+
*/
|
|
139
|
+
export interface TextDecoderLike {
|
|
140
|
+
decode(input: Uint8Array): string;
|
|
141
|
+
}
|
|
142
|
+
export type Zipped<T, U> = [a: T | undefined, b: U | undefined, idx: number];
|
|
143
|
+
export type ZippedEntries<Z> = Z extends Zipped<infer T, infer U> ? [T, U] : never;
|
|
144
|
+
export declare function zippedEntries<T, U>(zipped: Zipped<T, U>): ZippedEntries<Zipped<T, U>>;
|
|
145
|
+
/**
|
|
146
|
+
* Given two iterables, zip them together into a single iterable which yields pairs of elements.
|
|
147
|
+
*
|
|
148
|
+
* If one iterable is longer than the other, the shorter iterable will be padded with `undefined`.
|
|
149
|
+
*
|
|
150
|
+
* @param a The first iterable to zip.
|
|
151
|
+
* @param b The second iterable to zip.
|
|
152
|
+
* @yields Pairs of elements from the two iterables.
|
|
153
|
+
* @see {@linkcode zipAsync} for the asynchronous version.
|
|
154
|
+
*/
|
|
155
|
+
export declare function zipSync<T, U>(a: Iterable<T>, b: Iterable<U>): Generator<Zipped<T, U>>;
|
|
156
|
+
/**
|
|
157
|
+
* Given two iterables, zip them together into a single iterable which yields pairs of elements.
|
|
158
|
+
*
|
|
159
|
+
* If one iterable is longer than the other, the shorter iterable will be padded with `undefined`.
|
|
160
|
+
*
|
|
161
|
+
* @param a The first iterable to zip.
|
|
162
|
+
* @param b The second iterable to zip.
|
|
163
|
+
* @yields Pairs of elements from the two iterables.
|
|
164
|
+
* @see {@linkcode zipSync} for the synchronous version.
|
|
165
|
+
*/
|
|
166
|
+
export declare function zipAsync<T, U>(a: AsyncIterable<T> | Iterable<T>, b: AsyncIterable<U> | Iterable<U>): AsyncGenerator<[a: T | undefined, b: U | undefined, idx: number]>;
|
|
167
|
+
//# sourceMappingURL=shared.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":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,CAAC,CAAA;AAE5E,MAAM,MAAM,aAAa,CAAC,CAAC,IAAI,CAAC,SAAS,MAAM,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,KAAK,CAAA;AAElF,wBAAgB,aAAa,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAErF;AACD;;;;;;;;;GASG;AACH,wBAAiB,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAkBtF;AAED;;;;;;;;;GASG;AACH,wBAAuB,QAAQ,CAAC,CAAC,EAAE,CAAC,EACnC,CAAC,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,EACjC,CAAC,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,GAC/B,cAAc,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,SAAS,EAAE,CAAC,EAAE,CAAC,GAAG,SAAS,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC,CAkBnE"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
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
|
+
* Given a file resource, adds a `read` method to read a range of bytes.
|
|
14
|
+
*
|
|
15
|
+
* This allows the web `File` interface to be used as a byte range reader.
|
|
16
|
+
*/
|
|
17
|
+
export function applyReaderPolyfill(file) {
|
|
18
|
+
if ("read" in file && typeof file.read === "function") {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
Object.assign(file, {
|
|
22
|
+
async read(options = {}) {
|
|
23
|
+
const { position: start = 0, length = file.size, offset = 0 } = options;
|
|
24
|
+
const windowed = file.slice(start, start + length);
|
|
25
|
+
const bytes = (await windowed.bytes());
|
|
26
|
+
if (options.buffer) {
|
|
27
|
+
const destination = options.buffer;
|
|
28
|
+
destination.set(bytes, offset);
|
|
29
|
+
return destination;
|
|
30
|
+
}
|
|
31
|
+
return bytes;
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Type-predicate to determine if a value is a file resource.
|
|
37
|
+
*/
|
|
38
|
+
export function isFileResourceLike(input) {
|
|
39
|
+
return Boolean(input && typeof input === "object" && "slice" in input);
|
|
40
|
+
}
|
|
41
|
+
export function zippedEntries(zipped) {
|
|
42
|
+
return zipped.slice(0, 2);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Given two iterables, zip them together into a single iterable which yields pairs of elements.
|
|
46
|
+
*
|
|
47
|
+
* If one iterable is longer than the other, the shorter iterable will be padded with `undefined`.
|
|
48
|
+
*
|
|
49
|
+
* @param a The first iterable to zip.
|
|
50
|
+
* @param b The second iterable to zip.
|
|
51
|
+
* @yields Pairs of elements from the two iterables.
|
|
52
|
+
* @see {@linkcode zipAsync} for the asynchronous version.
|
|
53
|
+
*/
|
|
54
|
+
export function* zipSync(a, b) {
|
|
55
|
+
const aIterator = a[Symbol.iterator]();
|
|
56
|
+
const bIterator = b[Symbol.iterator]();
|
|
57
|
+
let index = 0;
|
|
58
|
+
while (true) {
|
|
59
|
+
const { done: aDone, value: aValue } = aIterator.next();
|
|
60
|
+
const { done: bDone, value: bValue } = bIterator.next();
|
|
61
|
+
if (aDone && bDone) {
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
64
|
+
yield [aValue, bValue, index];
|
|
65
|
+
index++;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Given two iterables, zip them together into a single iterable which yields pairs of elements.
|
|
70
|
+
*
|
|
71
|
+
* If one iterable is longer than the other, the shorter iterable will be padded with `undefined`.
|
|
72
|
+
*
|
|
73
|
+
* @param a The first iterable to zip.
|
|
74
|
+
* @param b The second iterable to zip.
|
|
75
|
+
* @yields Pairs of elements from the two iterables.
|
|
76
|
+
* @see {@linkcode zipSync} for the synchronous version.
|
|
77
|
+
*/
|
|
78
|
+
export async function* zipAsync(a, b) {
|
|
79
|
+
const aIterator = Symbol.asyncIterator in a ? a[Symbol.asyncIterator]() : a[Symbol.iterator]();
|
|
80
|
+
const bIterator = Symbol.asyncIterator in b ? b[Symbol.asyncIterator]() : b[Symbol.iterator]();
|
|
81
|
+
let index = 0;
|
|
82
|
+
while (true) {
|
|
83
|
+
const { done: aDone, value: aValue } = await aIterator.next();
|
|
84
|
+
const { done: bDone, value: bValue } = await bIterator.next();
|
|
85
|
+
if (aDone && bDone) {
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
yield [aValue, bValue, index];
|
|
89
|
+
index++;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=shared.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared.js","sourceRoot":"","sources":["../../lib/shared.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAoDH;;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;AA6ED;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CAA6B,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IAAI,KAAK,EAAE,CAAC;YACpB,MAAK;QACN,CAAC;QAED,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,CAAA;QAE7B,KAAK,EAAE,CAAA;IACR,CAAC;AACF,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Given an iterable collection, returns an async iterable, executing the callback on each batch.
|
|
8
|
+
*
|
|
9
|
+
* This is useful for batching asynchronous operations.
|
|
10
|
+
*
|
|
11
|
+
* @param collection The collection to batch.
|
|
12
|
+
* @param batchSize The size of each batch.
|
|
13
|
+
* @param callback The async callback to execute on each batch.
|
|
14
|
+
* @yields The result of each callback execution
|
|
15
|
+
*/
|
|
16
|
+
export declare function asyncParallelIterator<T, C extends (entry: T) => Promise<unknown>>(collection: Iterable<T> | AsyncIterable<T>, batchSize: number, callback: C, abortSignal?: AbortSignal): AsyncIterable<Awaited<ReturnType<C>>>;
|
|
17
|
+
/**
|
|
18
|
+
* Given an async iterable collection, returns an async iterable, yielding batches of items.
|
|
19
|
+
*
|
|
20
|
+
* This is useful for emitting asynchronous items in batches, such as when processing a stream of
|
|
21
|
+
* data.
|
|
22
|
+
*
|
|
23
|
+
* @yields Each batch of items.
|
|
24
|
+
*/
|
|
25
|
+
export declare function takeAsync<T>(collection: AsyncIterable<T>, batchSize: number): AsyncIterable<T[]>;
|
|
26
|
+
//# sourceMappingURL=take.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"take.d.ts","sourceRoot":"","sources":["../../lib/take.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;;;GASG;AACH,wBAAuB,qBAAqB,CAAC,CAAC,EAAE,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC,KAAK,OAAO,CAAC,OAAO,CAAC,EACvF,UAAU,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,EAC1C,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,CAAC,EACX,WAAW,CAAC,EAAE,WAAW,GACvB,aAAa,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAiDvC;AAED;;;;;;;GAOG;AACH,wBAAuB,SAAS,CAAC,CAAC,EAAE,UAAU,EAAE,aAAa,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,MAAM,GAAG,aAAa,CAAC,CAAC,EAAE,CAAC,CAgBvG"}
|
package/out/lib/take.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Given an iterable collection, returns an async iterable, executing the callback on each batch.
|
|
8
|
+
*
|
|
9
|
+
* This is useful for batching asynchronous operations.
|
|
10
|
+
*
|
|
11
|
+
* @param collection The collection to batch.
|
|
12
|
+
* @param batchSize The size of each batch.
|
|
13
|
+
* @param callback The async callback to execute on each batch.
|
|
14
|
+
* @yields The result of each callback execution
|
|
15
|
+
*/
|
|
16
|
+
export async function* asyncParallelIterator(collection, batchSize, callback, abortSignal) {
|
|
17
|
+
const iterator = Symbol.asyncIterator in collection ? collection[Symbol.asyncIterator]() : collection[Symbol.iterator]();
|
|
18
|
+
const runningTasks = new Map();
|
|
19
|
+
const results = new Map();
|
|
20
|
+
let iterationResult = await iterator.next();
|
|
21
|
+
while ((!iterationResult.done || results.size) && !abortSignal?.aborted) {
|
|
22
|
+
for (const [key, result] of results) {
|
|
23
|
+
yield result;
|
|
24
|
+
results.delete(key);
|
|
25
|
+
}
|
|
26
|
+
if (runningTasks.size >= batchSize) {
|
|
27
|
+
await Promise.race(runningTasks.values());
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
if (iterationResult.done) {
|
|
31
|
+
await Promise.all(runningTasks.values());
|
|
32
|
+
break;
|
|
33
|
+
}
|
|
34
|
+
const entry = iterationResult.value;
|
|
35
|
+
const futureResult = callback(entry).then((result) => {
|
|
36
|
+
runningTasks.delete(entry);
|
|
37
|
+
results.set(entry, result);
|
|
38
|
+
});
|
|
39
|
+
runningTasks.set(entry, futureResult);
|
|
40
|
+
iterationResult = await iterator.next();
|
|
41
|
+
}
|
|
42
|
+
if (!abortSignal || !abortSignal.aborted) {
|
|
43
|
+
await Promise.all(runningTasks.values());
|
|
44
|
+
for (const [key, result] of results) {
|
|
45
|
+
yield result;
|
|
46
|
+
results.delete(key);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Given an async iterable collection, returns an async iterable, yielding batches of items.
|
|
52
|
+
*
|
|
53
|
+
* This is useful for emitting asynchronous items in batches, such as when processing a stream of
|
|
54
|
+
* data.
|
|
55
|
+
*
|
|
56
|
+
* @yields Each batch of items.
|
|
57
|
+
*/
|
|
58
|
+
export async function* takeAsync(collection, batchSize) {
|
|
59
|
+
let buffer = [];
|
|
60
|
+
for await (const item of collection) {
|
|
61
|
+
buffer.push(item);
|
|
62
|
+
if (buffer.length === batchSize) {
|
|
63
|
+
yield buffer;
|
|
64
|
+
buffer = [];
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
if (buffer.length !== 0) {
|
|
68
|
+
yield buffer;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=take.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"take.js","sourceRoot":"","sources":["../../lib/take.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,SAAS,CAAC,CAAC,qBAAqB,CAC3C,UAA0C,EAC1C,SAAiB,EACjB,QAAW,EACX,WAA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AAC,CAAA;QAErC,eAAe,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAA;IACxC,CAAC;IAED,IAAI,CAAC,WAAW,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE,CAAC;QAC1C,MAAM,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,MAAM,EAAE,CAAC,CAAA;QAExC,KAAK,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,IAAI,OAAO,EAAE,CAAC;YACrC,MAAM,MAAM,CAAA;YAEZ,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;QACpB,CAAC;IACF,CAAC;AACF,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,SAAS,CAAC,CAAC,SAAS,CAAI,UAA4B,EAAE,SAAiB;IAClF,IAAI,MAAM,GAAQ,EAAE,CAAA;IAEpB,IAAI,KAAK,EAAE,MAAM,IAAI,IAAI,UAAU,EAAE,CAAC;QACrC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAEjB,IAAI,MAAM,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;YACjC,MAAM,MAAM,CAAA;YAEZ,MAAM,GAAG,EAAE,CAAA;QACZ,CAAC;IACF,CAAC;IAED,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACzB,MAAM,MAAM,CAAA;IACb,CAAC;AACF,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*/
|
|
6
|
+
import { PathLike, WriteStream } from "node:fs";
|
|
7
|
+
/**
|
|
8
|
+
* Callback for writing a line to a newline-delimited file.
|
|
9
|
+
*/
|
|
10
|
+
export interface WriteLineCallback {
|
|
11
|
+
/**
|
|
12
|
+
* Write a line to the file. The line should not contain a newline character.
|
|
13
|
+
*/
|
|
14
|
+
(content: string): Promise<void>;
|
|
15
|
+
/**
|
|
16
|
+
* Write a chunk to the file. The chunk should not contain a newline character.
|
|
17
|
+
*/
|
|
18
|
+
(chunk: any, encoding: BufferEncoding): Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
export interface NewlineWriter extends AsyncDisposable {
|
|
21
|
+
/**
|
|
22
|
+
* Write a line to the file.
|
|
23
|
+
*
|
|
24
|
+
* The content should not contain a newline character.
|
|
25
|
+
*/
|
|
26
|
+
write: WriteLineCallback;
|
|
27
|
+
dispose: () => Promise<void>;
|
|
28
|
+
writer: WriteStream;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Creates a writer for newline-delimited files.
|
|
32
|
+
*/
|
|
33
|
+
export declare function createNewlineWriter(filePath: PathLike): NewlineWriter;
|
|
34
|
+
//# sourceMappingURL=writer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"writer.d.ts","sourceRoot":"","sources":["../../lib/writer.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAqB,QAAQ,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAElE;;GAEG;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;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,QAAQ,GAAG,aAAa,CAmCrE"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*/
|
|
6
|
+
import { createWriteStream } from "node:fs";
|
|
7
|
+
/**
|
|
8
|
+
* Creates a writer for newline-delimited files.
|
|
9
|
+
*/
|
|
10
|
+
export function createNewlineWriter(filePath) {
|
|
11
|
+
const writer = createWriteStream(filePath);
|
|
12
|
+
const write = (content) => {
|
|
13
|
+
return new Promise((resolve, reject) => {
|
|
14
|
+
writer.write(content, "utf8", (error) => {
|
|
15
|
+
if (error) {
|
|
16
|
+
reject(error);
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
resolve();
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
const dispose = () => {
|
|
24
|
+
return new Promise((resolve, reject) => {
|
|
25
|
+
writer.close((error) => {
|
|
26
|
+
if (error) {
|
|
27
|
+
reject(error);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
resolve();
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
return {
|
|
35
|
+
write,
|
|
36
|
+
writer,
|
|
37
|
+
dispose,
|
|
38
|
+
[Symbol.asyncDispose]: dispose,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=writer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"writer.js","sourceRoot":"","sources":["../../lib/writer.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,iBAAiB,EAAyB,MAAM,SAAS,CAAA;AA2BlE;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAAC,QAAkB;IACrD,MAAM,MAAM,GAAG,iBAAiB,CAAC,QAAQ,CAAC,CAAA;IAE1C,MAAM,KAAK,GAAsB,CAAC,OAAO,EAAE,EAAE;QAC5C,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACtC,MAAM,CAAC,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,CAAC,KAAK,EAAE,EAAE;gBACvC,IAAI,KAAK,EAAE,CAAC;oBACX,MAAM,CAAC,KAAK,CAAC,CAAA;oBACb,OAAM;gBACP,CAAC;gBAED,OAAO,EAAE,CAAA;YACV,CAAC,CAAC,CAAA;QACH,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;oBACX,MAAM,CAAC,KAAK,CAAC,CAAA;oBACb,OAAM;gBACP,CAAC;gBAED,OAAO,EAAE,CAAA;YACV,CAAC,CAAC,CAAA;QACH,CAAC,CAAC,CAAA;IACH,CAAC,CAAA;IAED,OAAO;QACN,KAAK;QACL,MAAM;QACN,OAAO;QACP,CAAC,MAAM,CAAC,YAAY,CAAC,EAAE,OAAO;KAC9B,CAAA;AACF,CAAC"}
|