This repository has been archived on 2026-07-15. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
drive/frontend/node_modules/tus-js-client/lib/node/fileReader.js
Elijah 724d70e58b
Some checks failed
Automated Container Build / build-and-push (push) Failing after 12s
Inital build
2026-05-22 12:29:43 -07:00

34 lines
1 KiB
JavaScript

import { ReadStream } from 'fs'
import isStream from 'is-stream'
import BufferSource from './sources/BufferSource.js'
import getFileSource from './sources/FileSource.js'
import StreamSource from './sources/StreamSource.js'
export default class FileReader {
openFile(input, chunkSize) {
if (Buffer.isBuffer(input)) {
return Promise.resolve(new BufferSource(input))
}
if (input instanceof ReadStream && input.path != null) {
return getFileSource(input)
}
if (isStream.readable(input)) {
chunkSize = Number(chunkSize)
if (!Number.isFinite(chunkSize)) {
return Promise.reject(
new Error(
'cannot create source for stream without a finite value for the `chunkSize` option; specify a chunkSize to control the memory consumption',
),
)
}
return Promise.resolve(new StreamSource(input))
}
return Promise.reject(
new Error('source object may only be an instance of Buffer or Readable in this environment'),
)
}
}