-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Buffer is now a subtype of Uint8Array, so no special handling is required anymore
- Loading branch information
Showing
15 changed files
with
100 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
lib/node-conversions/browser-fallback.js → lib/node-utils/browser-fallback.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
export const NodeReadableStream = null; | ||
export const NodeBuffer = null; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { NodeReadableStream } from './node.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// This file is only included in the Node build | ||
export { Readable as NodeReadableStream } from 'node:stream'; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,16 @@ | ||
import { expect } from 'chai'; | ||
import { toStream, readToEnd } from '../lib/index.js'; | ||
import { toStream, readToEnd } from '@openpgp/web-stream-tools'; | ||
|
||
describe('Browser integration tests', () => { | ||
it('toStream/readToEnd', async () => { | ||
it('accepts readable stream', async () => { | ||
const input = 'chunk'; | ||
const streamedData = toStream('chunk'); | ||
const stream = new ReadableStream({ | ||
start(controller) { | ||
controller.enqueue(input); | ||
controller.close(); | ||
} | ||
}); | ||
const streamedData = toStream(stream); | ||
expect(await readToEnd(streamedData)).to.equal(input); | ||
}) | ||
}); | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { expect } from 'chai'; | ||
import { toStream, readToEnd, slice } from '@openpgp/web-stream-tools'; | ||
|
||
describe('Common integration tests', () => { | ||
it('toStream/readToEnd', async () => { | ||
const input = 'chunk'; | ||
const streamedData = toStream('chunk'); | ||
expect(await readToEnd(streamedData)).to.equal(input); | ||
}); | ||
|
||
it('slice', async () => { | ||
const input = 'another chunk'; | ||
const streamedData = toStream(input); | ||
const slicedStream = slice(streamedData, 8); | ||
expect(await readToEnd(slicedStream)).to.equal('chunk'); | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,49 @@ | ||
import { expect } from 'chai'; | ||
import { Readable } from 'stream'; | ||
import { ReadableStream as NodeWebReadableStream } from 'stream/web'; | ||
import { Readable as NodeNativeReadableStream } from 'node:stream'; | ||
import { ReadableStream as NodeWebReadableStream } from 'node:stream/web'; | ||
import { toStream, readToEnd } from '@openpgp/web-stream-tools'; | ||
import { ReadableStream as PolyfilledReadableStream } from 'web-streams-polyfill'; | ||
|
||
describe('Node integration tests', () => { | ||
it('throws on node native stream', async () => { | ||
const input = new Readable(); | ||
const input = new NodeNativeReadableStream(); | ||
expect(() => toStream(input)).to.throw(/Native Node streams are no longer supported/); | ||
}); | ||
|
||
it('accepts on node web stream', async () => { | ||
it('accepts node web stream', async () => { | ||
const input = 'chunk'; | ||
const stream = new NodeWebReadableStream({ | ||
start(controller) { | ||
controller.enqueue('chunk'); | ||
controller.enqueue(input); | ||
controller.close(); | ||
} | ||
}); | ||
const streamedData = toStream(stream); | ||
expect(await readToEnd(streamedData)).to.equal(input); | ||
}); | ||
|
||
it('toStream/readToEnd', async () => { | ||
it('returned node web stream can be converted into node native stream', async () => { | ||
const input = 'chunk'; | ||
const streamedData = toStream('chunk'); | ||
expect(await readToEnd(streamedData)).to.equal(input); | ||
}) | ||
}) | ||
const stream = new NodeWebReadableStream({ | ||
start(controller) { | ||
controller.enqueue(input); | ||
controller.close(); | ||
} | ||
}); | ||
const streamedData = toStream(stream); | ||
expect(NodeNativeReadableStream.fromWeb(streamedData)).to.exist; | ||
}); | ||
|
||
it('polyfilled web stream cannot be converted into node native stream', async () => { | ||
// this test is just to keep track that this behaviour is expected | ||
const input = 'chunk'; | ||
const stream = new PolyfilledReadableStream({ | ||
start(controller) { | ||
controller.enqueue(input); | ||
controller.close(); | ||
} | ||
}); | ||
const streamedData = toStream(stream); | ||
expect(() => NodeNativeReadableStream.fromWeb(streamedData)).to.throw(/must be an instance of ReadableStream/); | ||
}); | ||
}); |