Skip to content

Commit

Permalink
Merge pull request #15 from vmpowerio/fix-14
Browse files Browse the repository at this point in the history
Call end() on readable stream buffer to enable piping
  • Loading branch information
Steven Edouard authored Jan 10, 2017
2 parents 4e50a1b + acfeb7a commit 0cdf7fa
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class ChartjsNode {
chunkSize: 2048 // in bytes.
});
readableStream.put(buffer);
readableStream.stop();
return {
stream: readableStream,
length: buffer.length
Expand Down
17 changes: 16 additions & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,22 @@ describe('chartjs', function () {
})
.then(imageStream => {
assert(imageStream.stream instanceof stream.Readable);
debug('Sucessfully wrote image to a Readable stream');
var length = imageStream.length;
var readLength = 0;
return new Promise((resolve, reject) => {
imageStream.stream.on('data', d => {
readLength += d.length;
if (readLength === length) {
debug('Sucessfully wrote image to a Readable stream');
resolve();
}
});
setTimeout(() => {
debug('length: ' + length);
debug('readLength: ' + readLength);
reject('Failed to read complete chart image stream in time');
}, 1000);
});
});
});
it('should return the image as data url', function () {
Expand Down

0 comments on commit 0cdf7fa

Please sign in to comment.