-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added tests for JSONL + related fixes.
- Loading branch information
Showing
4 changed files
with
39 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,16 @@ | ||
/// <reference types="node" /> | ||
|
||
import {Buffer} from 'node:buffer'; | ||
|
||
export = parser; | ||
|
||
interface OutputItem { | ||
key: number; | ||
value: unknown; | ||
value: any; | ||
} | ||
|
||
type Reviver = (this: unknown, key: string, value: unknown) => unknown; | ||
|
||
declare function parser(reviver?: Reviver): AsyncIterableIterator<OutputItem>; | ||
declare function parser( | ||
reviver?: Reviver | ||
): (x: string | Buffer) => AsyncGenerator<OutputItem, void, unknown>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import chain, {type Arg0, type Ret, type ChainItem} from 'stream-chain'; | ||
|
||
import parser from 'stream-chain/jsonl/parser.js'; | ||
import parserStream from 'stream-chain/jsonl/parserStream.js'; | ||
import stringerStream from 'stream-chain/jsonl/stringerStream.js'; | ||
|
||
import fs, { createReadStream, createWriteStream } from 'node:fs'; | ||
|
||
const pipeline1 = chain([ | ||
createReadStream('input.json'), | ||
parser(), | ||
({value}: {value: number}) => value + 1, | ||
stringerStream(), | ||
createWriteStream('output.json') | ||
] as const); | ||
|
||
void pipeline1; | ||
|
||
const pipeline2 = chain([ | ||
createReadStream('input.json'), | ||
parserStream(), | ||
({value}: {value: number}) => value + 1, | ||
stringerStream(), | ||
createWriteStream('output.json') | ||
] as const); | ||
|
||
void pipeline2; |