UNPKG

read-excel-file

Version:

Read `.xlsx` files in a web browser or in Node.js

24 lines (21 loc) 961 B
import fs from 'node:fs'; import { Blob } from 'node:buffer'; import Stream, { Readable } from 'node:stream'; /** * Converts Node.js input argument to a stream. * @param {(string|Stream|Buffer|Blob)} input - A Node.js readable stream or a `Buffer` or a `Blob` or a path to a file. * @returns {Stream} */ export default function convertInputToNodeStream(input) { return input instanceof Stream ? input : input instanceof Buffer ? createReadableStreamFromBuffer(input) : input instanceof Blob ? createReadableStreamFromBlob(input) : fs.createReadStream(input); } // Creates a readable stream from a `Buffer`. function createReadableStreamFromBuffer(buffer) { return Readable.from(buffer); } // Creates a readable stream from a `Blob`. function createReadableStreamFromBlob(blob) { // Convert a web `ReadableStream` to a Node.js `Readable` `Stream`. return Readable.fromWeb(blob.stream()); } //# sourceMappingURL=convertInputToNodeStream.js.map