-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.ts
54 lines (42 loc) · 1.46 KB
/
test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { ConcatenatedJSONParseStream, JSONLinesParseStream } from "../mod.ts";
Deno.test(async function read_jsonlines() {
const url = new URL("./json-lines.jsonl", import.meta.url);
const { body } = await fetch(`${url}`);
const readable = body!
.pipeThrough(new TextDecoderStream())
.pipeThrough(new JSONLinesParseStream());
for await (const data of readable) {
console.log(data);
}
});
Deno.test(async function read_ndjson() {
const url = new URL("./nd-json.ndjson", import.meta.url);
const { body } = await fetch(`${url}`);
const readable = body!
.pipeThrough(new TextDecoderStream())
.pipeThrough(new JSONLinesParseStream());
for await (const data of readable) {
console.log(data);
}
});
Deno.test(async function read_json_seq() {
const url = new URL("./json-seq.json-seq", import.meta.url);
const { body } = await fetch(`${url}`);
const recordSeparator = "\x1E";
const readable = body!
.pipeThrough(new TextDecoderStream())
.pipeThrough(new JSONLinesParseStream({ separator: recordSeparator }));
for await (const data of readable) {
console.log(data);
}
});
Deno.test(async function read_concat_json() {
const url = new URL("./concat-json.concat-json", import.meta.url);
const { body } = await fetch(`${url}`);
const readable = body!
.pipeThrough(new TextDecoderStream())
.pipeThrough(new ConcatenatedJSONParseStream());
for await (const data of readable) {
console.log(data);
}
});