/** * API expecting a stream as parameter and returning the same stream with a prefix. * * @async * @param {Readable} stream - incoming stream * @returns {Readable} incoming stream prefixed 'here is a prefix -- ' */ async streamHandling (stream) { assert(stream instanceof Readable) const prefix = new BufferList() prefix.append('here is a prefix -- ', 'utf8') return multistream([prefix, stream]) }
it('should send and receive streams', async () => { const {response, result} = await new Promise((resolve, reject) => { let response const output = new BufferList() const input = new BufferList() input.pipe( req.post(`${server.info.uri}/api/sample/streamHandling`) .on('response', r => { response = r }) .on('end', () => { resolve({response, result: output.toString()}) }) ) .pipe(output) .on('error', reject) input.append('here is the message body', 'utf8') }) assert(result === 'here is a prefix -- here is the message body') assert(response.headers['x-service-crc'] === checksum) assert(response.headers['transfer-encoding'] === 'chunked') assert(!response.headers['content-type']) })
data = new BufferList() data.append(d) })