Skip to content

Commit

Permalink
fix: stringify should respect Buffer.from default encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
EqualMa committed Aug 15, 2020
1 parent af512f3 commit 44f5b5d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
3 changes: 2 additions & 1 deletion README.md
Expand Up @@ -92,7 +92,8 @@ export interface JsonLinesStringifyOptions<V> {
* NOTE that [the standard jsonlines](http://jsonlines.org/)
* requires `utf8` as file encoding
*
* Defaults to `utf8`
* Defaults to `Buffer.from` default encoding,
* which is `utf8`.
*/
encoding?: BufferEncoding;

Expand Down
7 changes: 4 additions & 3 deletions src/stringify.ts
Expand Up @@ -10,7 +10,8 @@ export interface JsonLinesStringifyOptions<V> {
* NOTE that [the standard jsonlines](http://jsonlines.org/)
* requires `utf8` as file encoding
*
* Defaults to `utf8`
* Defaults to `Buffer.from` default encoding,
* which is `utf8`.
*/
encoding?: BufferEncoding;

Expand Down Expand Up @@ -46,15 +47,15 @@ export interface JsonLinesStringifyOptions<V> {
export class JsonLinesStringifyStream<V> extends Transform {
#stringify: (v: V) => string | Promise<string>;

readonly encoding: BufferEncoding;
readonly encoding: BufferEncoding | undefined;
readonly lineSep: string;

constructor(options?: JsonLinesStringifyOptions<V>) {
super({
writableObjectMode: true,
});

this.encoding = options?.encoding ?? "utf8";
this.encoding = options?.encoding;
this.lineSep = getLineSepString(options?.lineSep ?? "lf");
this.#stringify = options?.stringify ?? JSON.stringify;
}
Expand Down

0 comments on commit 44f5b5d

Please sign in to comment.