Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/streams.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ async function pipe(input, target, {
preventAbort = false,
preventCancel = false
} = {}) {
if (isStream(input) && !isArrayStream(input)) {
if (isStream(input) && !isArrayStream(input) && !isArrayStream(target)) {
input = toStream(input);
try {
if (input[externalBuffer]) {
Expand All @@ -129,7 +129,9 @@ async function pipe(input, target, {
} catch(e) {}
return;
}
input = toArrayStream(input);
if (!isStream(input)) {
input = toArrayStream(input);
}
const reader = getReader(input);
const writer = getWriter(target);
try {
Expand Down Expand Up @@ -566,6 +568,7 @@ function getWriter(input) {
export {
ArrayStream,
toStream,
toArrayStream,
concatStream,
concat,
getReader,
Expand Down
39 changes: 36 additions & 3 deletions test/common.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { expect } from 'chai';
import { toStream, readToEnd, slice } from '@openpgp/web-stream-tools';
// @ts-ignore Missing type definitions
import { toStream, toArrayStream, readToEnd, slice, pipe, ArrayStream } from '@openpgp/web-stream-tools';

describe('Common integration tests', () => {
it('toStream/readToEnd', async () => {
Expand All @@ -13,5 +14,37 @@ describe('Common integration tests', () => {
const streamedData = toStream(input);
const slicedStream = slice(streamedData, 8);
expect(await readToEnd(slicedStream)).to.equal('chunk');
})
})
});

it('pipe from stream to stream', async () => {
const input = 'chunk';
const inputStream = toStream(input);
const outputStream = new TransformStream();
pipe(inputStream, outputStream.writable);
expect(await readToEnd(outputStream.readable)).to.equal('chunk');
});

it('pipe from stream to arraystream', async () => {
const input = 'chunk';
const inputStream = toStream(input);
const outputStream = new ArrayStream();
pipe(inputStream, outputStream);
expect(await readToEnd(outputStream)).to.equal('chunk');
});

it('pipe from arraystream to stream', async () => {
const input = 'chunk';
const inputStream = toArrayStream(input);
const outputStream = new TransformStream();
pipe(inputStream, outputStream.writable);
expect(await readToEnd(outputStream.readable)).to.equal('chunk');
});

it('pipe from arraystream to arraystream', async () => {
const input = 'chunk';
const inputStream = toArrayStream(input);
const outputStream = new ArrayStream();
pipe(inputStream, outputStream);
expect(await readToEnd(outputStream)).to.equal('chunk');
});
});