Skip to content

Commit 0cdf7fa

Browse files
author
Steven Edouard
authored
Merge pull request #15 from vmpowerio/fix-14
Call end() on readable stream buffer to enable piping
2 parents 4e50a1b + acfeb7a commit 0cdf7fa

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ class ChartjsNode {
9696
chunkSize: 2048 // in bytes.
9797
});
9898
readableStream.put(buffer);
99+
readableStream.stop();
99100
return {
100101
stream: readableStream,
101102
length: buffer.length

test/index.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,22 @@ describe('chartjs', function () {
104104
})
105105
.then(imageStream => {
106106
assert(imageStream.stream instanceof stream.Readable);
107-
debug('Sucessfully wrote image to a Readable stream');
107+
var length = imageStream.length;
108+
var readLength = 0;
109+
return new Promise((resolve, reject) => {
110+
imageStream.stream.on('data', d => {
111+
readLength += d.length;
112+
if (readLength === length) {
113+
debug('Sucessfully wrote image to a Readable stream');
114+
resolve();
115+
}
116+
});
117+
setTimeout(() => {
118+
debug('length: ' + length);
119+
debug('readLength: ' + readLength);
120+
reject('Failed to read complete chart image stream in time');
121+
}, 1000);
122+
});
108123
});
109124
});
110125
it('should return the image as data url', function () {

0 commit comments

Comments
 (0)