Skip to content

Commit

Permalink
fix performance issue in stream to performance and bump packages
Browse files Browse the repository at this point in the history
  • Loading branch information
derduher committed May 26, 2020
1 parent a476e92 commit 05f6139
Show file tree
Hide file tree
Showing 5 changed files with 741 additions and 257 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 6.1.5

- performance improvement for streamToPromise #307

## 6.1.4

- remove stale files from dist #298
Expand Down
8 changes: 4 additions & 4 deletions lib/sitemap-stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,21 +136,21 @@ export class SitemapStream extends Transform {
*/
export function streamToPromise(stream: Readable): Promise<Buffer> {
return new Promise((resolve, reject): void => {
let drain: Buffer;
let drain: Buffer[];
stream
.pipe(
new Writable({
write(chunk, enc, next): void {
if (!drain) {
drain = chunk;
drain = [chunk];
} else {
drain = Buffer.concat([drain, chunk]);
drain.push(chunk);
}
next();
},
})
)
.on('error', reject)
.on('finish', () => resolve(drain));
.on('finish', () => resolve(Buffer.concat(drain)));
});
}
Loading

0 comments on commit 05f6139

Please sign in to comment.