-
Notifications
You must be signed in to change notification settings - Fork 300
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move all node-related source files to TypeScript
- Loading branch information
Showing
13 changed files
with
287 additions
and
204 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import BaseUpload, { | ||
UploadOptions, | ||
defaultOptions as baseDefaultOptions, | ||
terminate, | ||
} from '../upload' | ||
import NoopUrlStorage from '../noopUrlStorage' | ||
import { enableDebugLog } from '../logger' | ||
import DetailedError from '../error' | ||
|
||
import { FileUrlStorage, canStoreURLs } from './urlStorage' | ||
import DefaultHttpStack from './httpStack' | ||
import FileReader from './fileReader' | ||
import fingerprint from './fileSignature' | ||
import StreamSource from './sources/StreamSource' | ||
|
||
import { ReadStream } from 'fs' | ||
import { Readable } from 'stream' | ||
|
||
const defaultOptions = { | ||
...baseDefaultOptions, | ||
httpStack: new DefaultHttpStack(), | ||
fileReader: new FileReader(), | ||
urlStorage: new NoopUrlStorage(), | ||
fingerprint, | ||
} | ||
|
||
export type FileTypes = Buffer | Readable | ReadStream | ||
export type FileSliceTypes = Buffer | ReadStream | ||
|
||
class Upload extends BaseUpload<FileTypes, FileSliceTypes> { | ||
constructor(file: FileTypes, options: Partial<UploadOptions<FileTypes, FileSliceTypes>> = {}) { | ||
const allOpts = { ...defaultOptions, ...options } | ||
super(file, allOpts) | ||
} | ||
|
||
static terminate(url: string, options: Partial<UploadOptions<FileTypes, FileSliceTypes>> = {}) { | ||
const allOpts = { ...defaultOptions, ...options } | ||
return terminate(url, allOpts) | ||
} | ||
} | ||
|
||
// The Node.js environment does not have restrictions which may cause | ||
// tus-js-client not to function. | ||
const isSupported = true | ||
|
||
// The usage of the commonjs exporting syntax instead of the new ECMAScript | ||
// one is actually inteded and prevents weird behaviour if we are trying to | ||
// import this module in another module using Babel. | ||
export { | ||
Upload, | ||
defaultOptions, | ||
isSupported, | ||
// Make FileUrlStorage module available as it will not be set by default. | ||
FileUrlStorage, | ||
canStoreURLs, | ||
enableDebugLog, | ||
DefaultHttpStack, | ||
DetailedError, | ||
StreamSource, | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { FileSource } from '../../upload' | ||
|
||
export default class BufferSource implements FileSource<Buffer> { | ||
size: number | ||
private _buffer: Buffer | ||
|
||
constructor(buffer: Buffer) { | ||
this._buffer = buffer | ||
this.size = buffer.length | ||
} | ||
|
||
slice(start: number, end: number) { | ||
const value: Buffer & { size?: number } = this._buffer.slice(start, end) | ||
value.size = value.length | ||
const done = end >= this.size | ||
return Promise.resolve({ value, done }) | ||
} | ||
|
||
close() {} | ||
} |
Oops, something went wrong.