Init
This commit is contained in:
41
node_modules/get-stream/source/string.js
generated
vendored
Normal file
41
node_modules/get-stream/source/string.js
generated
vendored
Normal file
@ -0,0 +1,41 @@
|
||||
import {getStreamContents} from './contents.js';
|
||||
import {
|
||||
identity,
|
||||
getContentsProperty,
|
||||
throwObjectStream,
|
||||
getLengthProperty,
|
||||
} from './utils.js';
|
||||
|
||||
export async function getStreamAsString(stream, options) {
|
||||
return getStreamContents(stream, stringMethods, options);
|
||||
}
|
||||
|
||||
const initString = () => ({contents: '', textDecoder: new TextDecoder()});
|
||||
|
||||
const useTextDecoder = (chunk, {textDecoder}) => textDecoder.decode(chunk, {stream: true});
|
||||
|
||||
const addStringChunk = (convertedChunk, {contents}) => contents + convertedChunk;
|
||||
|
||||
const truncateStringChunk = (convertedChunk, chunkSize) => convertedChunk.slice(0, chunkSize);
|
||||
|
||||
const getFinalStringChunk = ({textDecoder}) => {
|
||||
const finalChunk = textDecoder.decode();
|
||||
return finalChunk === '' ? undefined : finalChunk;
|
||||
};
|
||||
|
||||
const stringMethods = {
|
||||
init: initString,
|
||||
convertChunk: {
|
||||
string: identity,
|
||||
buffer: useTextDecoder,
|
||||
arrayBuffer: useTextDecoder,
|
||||
dataView: useTextDecoder,
|
||||
typedArray: useTextDecoder,
|
||||
others: throwObjectStream,
|
||||
},
|
||||
getSize: getLengthProperty,
|
||||
truncateChunk: truncateStringChunk,
|
||||
addChunk: addStringChunk,
|
||||
getFinalChunk: getFinalStringChunk,
|
||||
finalize: getContentsProperty,
|
||||
};
|
||||
Reference in New Issue
Block a user