(input?: File | Response | BufferLike | StreamLike, modDate?: any, mode?: number)
| 24 | export function normalizeInput(input: File | Response | BufferLike | StreamLike, modDate?: any, mode?: number): ZipFileDescription; |
| 25 | export function normalizeInput(input: undefined, modDate?: any, mode?: number): ZipFolderDescription; |
| 26 | export function normalizeInput(input?: File | Response | BufferLike | StreamLike, modDate?: any, mode?: number): ZipEntryDescription { |
| 27 | if (modDate !== undefined && !(modDate instanceof Date)) modDate = new Date(modDate) |
| 28 | |
| 29 | const isFile = input !== undefined |
| 30 | |
| 31 | if(!mode) { |
| 32 | mode = isFile ? 0o664 : 0o775 |
| 33 | } |
| 34 | |
| 35 | if (input instanceof File) return { |
| 36 | isFile, |
| 37 | modDate: modDate || new Date(input.lastModified), |
| 38 | bytes: input.stream(), |
| 39 | mode |
| 40 | } |
| 41 | if (input instanceof Response) return { |
| 42 | isFile, |
| 43 | modDate: modDate || new Date(input.headers.get("Last-Modified") || Date.now()), |
| 44 | bytes: input.body!, |
| 45 | mode |
| 46 | } |
| 47 | |
| 48 | if (modDate === undefined) modDate = new Date() |
| 49 | else if (isNaN(modDate)) throw new Error("Invalid modification date.") |
| 50 | if (!isFile) return { isFile, modDate, mode } |
| 51 | if (typeof input === "string") return { isFile, modDate, bytes: encodeString(input), mode } |
| 52 | if (input instanceof Blob) return { isFile, modDate, bytes: input.stream(), mode } |
| 53 | if (input instanceof Uint8Array || input instanceof ReadableStream) return { isFile, modDate, bytes: input, mode } |
| 54 | if (input instanceof ArrayBuffer || ArrayBuffer.isView(input)) return { isFile, modDate, bytes: makeUint8Array(input), mode } |
| 55 | if (Symbol.asyncIterator in input) return { isFile, modDate, bytes: ReadableFromIterator(input[Symbol.asyncIterator]()), mode } |
| 56 | throw new TypeError("Unsupported input format.") |
| 57 | } |
| 58 | |
| 59 | export function ReadableFromIterator<T extends BufferLike>(iter: AsyncIterator<T>, upstream: AsyncIterator<any> = iter) { |
| 60 | return new ReadableStream<Uint8Array>({ |
no test coverage detected
searching dependent graphs…