import { assertInRequest } from "@miniflare/shared" ; export function isBufferSource ( chunk ) { return chunk instanceof ArrayBuffer || ArrayBuffer . isView ( chunk ) ; } export function bufferSourceToArray ( chunk ) { if ( chunk instanceof Uint8Array ) { return chunk ; } else if ( chunk instanceof ArrayBuffer ) { return new Uint8Array ( chunk ) ; } else { return new Uint8Array ( chunk . buffer , chunk . byteOffset , chunk . byteLength ) ; } } export function buildNotBufferSourceError ( value ) { const isString = typeof value === "string" ; return ( "This TransformStream is being used as a byte stream, but received " + ( isString ? "a string on its writable side. If you wish to write a string, " + "you'll probably want to explicitly UTF-8-encode it with TextEncoder." : "an object of non-ArrayBuffer/ArrayBufferView type on its writable side." ) ) ; } export function assertsInRequest < Args extends any [ ] , Return > ( func , assert ) { return assert ? ( ... args ) => { assertInRequest ( ) ; return func ( ... args ) ; } : func ; }