Skip to content

Commit

Permalink
Support ArrayBuffer stream chunks
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Aug 9, 2023
1 parent 4217c05 commit 9de9884
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
6 changes: 6 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ const getChunkType = chunk => {

const prototypeName = objectToString.call(chunk);

if (prototypeName === '[object ArrayBuffer]') {
return 'arrayBuffer';
}

if (prototypeName === '[object DataView]') {
return 'dataView';
}
Expand Down Expand Up @@ -123,6 +127,7 @@ const chunkTypes = {
convertChunk: {
string: useBufferFrom,
buffer: identity,
arrayBuffer: useBufferFrom,
dataView: useBufferFromWithOffset,
typedArray: useBufferFromWithOffset,
others: throwObjectStream,
Expand All @@ -133,6 +138,7 @@ const chunkTypes = {
convertChunk: {
string: identity,
buffer: useTextDecoder,
arrayBuffer: useTextDecoder,
dataView: useTextDecoder,
typedArray: useTextDecoder,
others: throwObjectStream,
Expand Down
3 changes: 3 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const getStreamToString = async (t, inputStream) => {

test('get stream from string to string', getStreamToString, fixtureString);
test('get stream from buffer to string', getStreamToString, fixtureBuffer);
test('get stream from arrayBuffer to string', getStreamToString, fixtureArrayBuffer);
test('get stream from typedArray to string', getStreamToString, fixtureTypedArray);
test('get stream from typedArray with offset to string', getStreamToString, fixtureTypedArrayWithOffset);
test('get stream from uint16Array to string', getStreamToString, fixtureUint16Array);
Expand All @@ -64,6 +65,7 @@ const getStreamToBuffer = async (t, inputStream) => {

test('get stream from string to buffer', getStreamToBuffer, fixtureString);
test('get stream from buffer to buffer', getStreamToBuffer, fixtureBuffer);
test('get stream from arrayBuffer to buffer', getStreamToBuffer, fixtureArrayBuffer);
test('get stream from typedArray to buffer', getStreamToBuffer, fixtureTypedArray);
test('get stream from typedArray with offset to buffer', getStreamToBuffer, fixtureTypedArrayWithOffset);
test('get stream from uint16Array to buffer', getStreamToBuffer, fixtureUint16Array);
Expand Down Expand Up @@ -124,6 +126,7 @@ const checkMaxBuffer = async (t, setupFunction, longValue, shortValue) => {

test('maxBuffer throws when size is exceeded with a string', checkMaxBuffer, setup, longString, fixtureString);
test('maxBuffer throws when size is exceeded with a buffer', checkMaxBuffer, setupBuffer, longBuffer, fixtureBuffer);
test('maxBuffer throws when size is exceeded with an arrayBuffer', checkMaxBuffer, setupBuffer, longArrayBuffer, fixtureArrayBuffer);
test('maxBuffer throws when size is exceeded with a typedArray', checkMaxBuffer, setupBuffer, longTypedArray, fixtureTypedArray);
test('maxBuffer throws when size is exceeded with an uint16Array', checkMaxBuffer, setupBuffer, longUint16Array, fixtureUint16Array);
test('maxBuffer throws when size is exceeded with a dataView', checkMaxBuffer, setupBuffer, longDataView, fixtureDataView);
Expand Down

0 comments on commit 9de9884

Please sign in to comment.