forked from aadsm/jsmediatags
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Did some general fixer-uppers to the codebase! Now it's more ES6-friendly in some spots, it consistently uses double-quotes now, and part of the ES6-friendly bits, now arrow functions are used a bit more, and any var declaration that's modified once is now a const declaration :) Forgot to include some links that helped out for the last few commits: nodejs/help#3902 https://stackoverflow.com/questions/35470511/setting-up-tsconfig-with-spec-test-folder https://jestjs.io/docs/ecmascript-modules https://khalilstemmler.com/blogs/typescript/abstract-class/ (Going to look into if this is what MediaFileReader should instead be made with. Haven't used this before!) https://stackoverflow.com/questions/45251664/derive-union-type-from-tuple-array-values (THIS IS FREAKING EPIC, big thanks to this post)
- Loading branch information
1 parent
9d2e48f
commit 1389d1f
Showing
21 changed files
with
881 additions
and
859 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,36 @@ | ||
import ChunkedFileData from './ChunkedFileData.js'; | ||
import MediaFileReader from './MediaFileReader.js'; | ||
import ChunkedFileData from "./ChunkedFileData.js"; | ||
import MediaFileReader from "./MediaFileReader.js"; | ||
|
||
import type { LoadCallbackType } from './FlowTypes.js'; | ||
import type { LoadCallbackType } from "./FlowTypes.js"; | ||
|
||
export default class ArrayBufferFileReader extends MediaFileReader { | ||
declare _buffer: ArrayBuffer; | ||
declare _fileData: ChunkedFileData; | ||
declare _size: number; | ||
declare _buffer: ArrayBuffer; | ||
declare _fileData: ChunkedFileData; | ||
declare _size: number; | ||
|
||
constructor(buffer: ArrayBuffer) { | ||
super(); | ||
this._buffer = buffer; | ||
this._fileData = new ChunkedFileData(); | ||
} | ||
constructor(buffer: ArrayBuffer) { | ||
super(); | ||
this._buffer = buffer; | ||
this._fileData = new ChunkedFileData(); | ||
} | ||
|
||
static canReadFile(file: any): boolean { | ||
return typeof ArrayBuffer === 'function' && file instanceof ArrayBuffer | ||
} | ||
static canReadFile(file: any): boolean { | ||
return file instanceof ArrayBuffer | ||
} | ||
|
||
_init(callbacks: LoadCallbackType): void { | ||
this._size = this._buffer.byteLength; | ||
setTimeout(callbacks.onSuccess, 1); | ||
} | ||
_init({ onSuccess }: LoadCallbackType): void { | ||
this._size = this._buffer.byteLength; | ||
setTimeout(onSuccess, 1); | ||
} | ||
|
||
loadRange(range: [number, number], callbacks: LoadCallbackType): void { | ||
var arrayBuf = this._buffer.slice(range[0], range[1] + 1); | ||
var viewData = new Uint8Array(arrayBuf); | ||
this._fileData.addData(range[0], viewData); | ||
callbacks.onSuccess(); | ||
} | ||
loadRange(range: [number, number], { onSuccess }: LoadCallbackType): void { | ||
const arrayBuf = this._buffer.slice(range[0], range[1] + 1); | ||
const viewData = new Uint8Array(arrayBuf); | ||
this._fileData.addData(range[0], viewData); | ||
onSuccess(); | ||
} | ||
|
||
getByteAt(offset: number): number { | ||
return this._fileData.getByteAt(offset); | ||
} | ||
getByteAt(offset: number): number { | ||
return this._fileData.getByteAt(offset); | ||
} | ||
} |
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 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
Oops, something went wrong.