@epfml/discojs-web 3.0.1-p20241203151748.0 → 3.0.1-p20241206154707.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/dist/loaders/text.js +0 -21
- package/package.json +1 -1
package/dist/loaders/text.js
CHANGED
|
@@ -1,30 +1,9 @@
|
|
|
1
1
|
import { Dataset } from "@epfml/discojs";
|
|
2
|
-
class LineStream extends TransformStream {
|
|
3
|
-
constructor() {
|
|
4
|
-
let current_line = "";
|
|
5
|
-
super({
|
|
6
|
-
transform: (chunk, controller) => {
|
|
7
|
-
const [head, ...lines] = chunk.split(/\r\n|\r|\n/);
|
|
8
|
-
const first_line = current_line + head;
|
|
9
|
-
if (lines.length === 0) {
|
|
10
|
-
current_line = first_line;
|
|
11
|
-
return;
|
|
12
|
-
}
|
|
13
|
-
controller.enqueue(first_line);
|
|
14
|
-
for (const line of lines.slice(0, -1))
|
|
15
|
-
controller.enqueue(line);
|
|
16
|
-
current_line = lines[lines.length - 1];
|
|
17
|
-
},
|
|
18
|
-
flush: (controller) => controller.enqueue(current_line),
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
2
|
export function load(file) {
|
|
23
3
|
return new Dataset(async function* () {
|
|
24
4
|
const reader = file
|
|
25
5
|
.stream()
|
|
26
6
|
.pipeThrough(new TextDecoderStream())
|
|
27
|
-
.pipeThrough(new LineStream())
|
|
28
7
|
.getReader();
|
|
29
8
|
while (true) {
|
|
30
9
|
const { value: chunk, done } = await reader.read();
|