@jsreport/jsreport-core
Advanced tools
Comparing version 4.2.0 to 4.2.1
@@ -64,3 +64,3 @@ const extend = require('node.extend.without.arrays') | ||
if (isReadableStream(bufOrStreamOrPath)) { | ||
if (isNodeReadableStream(bufOrStreamOrPath) || isWebReadableStream(bufOrStreamOrPath)) { | ||
if (outputImpl instanceof BufferOutput) { | ||
@@ -112,3 +112,3 @@ outputImpl = new StreamOutput(reporter, requestId) | ||
setBuffer (buf) { | ||
// we need to ensure that the buffer is an actually buffer instance, | ||
// we need to ensure that the buffer is a buffer instance, | ||
// so when receiving Uint8Array we convert it to a buffer | ||
@@ -203,4 +203,7 @@ this.buffer = Buffer.isBuffer(buf) ? buf : Buffer.from(buf) | ||
async setStream (stream) { | ||
// we need to ensure that the stream used in pipeline is node.js readable stream instance, | ||
// so when receiving Web ReadableStream we convert it to node.js readable stream | ||
const inputStream = isNodeReadableStream(stream) ? stream : Readable.fromWeb(stream) | ||
const { stream: responseFileStream } = await this.reporter.writeTempFileStream(this.filename) | ||
await pipeline(stream, responseFileStream) | ||
await pipeline(inputStream, responseFileStream) | ||
} | ||
@@ -226,3 +229,3 @@ | ||
// from https://github.com/sindresorhus/is-stream/blob/main/index.js | ||
function isReadableStream (stream) { | ||
function isNodeReadableStream (stream) { | ||
return ( | ||
@@ -232,5 +235,20 @@ stream !== null && | ||
typeof stream.pipe === 'function' && | ||
stream.readable !== false && typeof stream._read === 'function' && | ||
typeof stream._readableState === 'object' | ||
typeof stream.read === 'function' && | ||
typeof stream.readable === 'boolean' && | ||
typeof stream.readableObjectMode === 'boolean' && | ||
typeof stream.destroy === 'function' && | ||
typeof stream.destroyed === 'boolean' | ||
) | ||
} | ||
function isWebReadableStream (stream) { | ||
return ( | ||
stream !== null && | ||
typeof stream === 'object' && | ||
typeof stream.locked === 'boolean' && | ||
typeof stream.cancel === 'function' && | ||
typeof stream.getReader === 'function' && | ||
typeof stream.pipeTo === 'function' && | ||
typeof stream.pipeThrough === 'function' | ||
) | ||
} |
{ | ||
"name": "@jsreport/jsreport-core", | ||
"version": "4.2.0", | ||
"version": "4.2.1", | ||
"description": "javascript based business reporting", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -285,2 +285,7 @@ # @jsreport/jsreport-core | ||
### 4.2.0 | ||
- the response object has new structure and api, the `response.output` is new addition and contains different methods to work with the response output. the `response.content`, `response.stream` are now soft deprecated (will be removed in future versions) | ||
- the internal architecture has been updated to support working with template content and report output as streams, this means that the render will be able to handle and produce bigger reports without getting hit by out of memory errors | ||
### 4.1.0 | ||
@@ -287,0 +292,0 @@ |
408591
9890
426