diff --git a/lib/functions.ts b/lib/functions.ts index 50add7e..a5a72a9 100644 --- a/lib/functions.ts +++ b/lib/functions.ts @@ -35,17 +35,23 @@ export function isFicmasHidden(story: IStory): boolean { ); } -export function stringifyStream(stream: GridFSBucketReadStream): Promise { +export function bufferizeStream(stream: GridFSBucketReadStream): Promise { let chunks: Buffer[] = []; + return new Promise((res, rej) => { stream.on("data", (c) => chunks.push(Buffer.from(c))); stream.on("error", (err) => { rej(err); }); - stream.on("end", () => res(Buffer.concat(chunks).toString("utf-8"))); + stream.on("end", () => res(Buffer.concat(chunks))); }); } +export async function stringifyStream(stream: GridFSBucketReadStream): Promise { + let str = await bufferizeStream(stream); + return str.toString("utf-8"); +} + export function norm(text: string): string { return text .replace(/\n/g, "
")