mirror of
https://github.com/arcodange-org/mediabunny.git
synced 2026-09-28 03:13:51 +02:00
Add explicit disposability to Inputs (#126)
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
import { InputDisposedError } from './input';
|
||||
import { assert, clamp, getUint24, MaybePromise, toDataView } from './misc';
|
||||
import { Source } from './source';
|
||||
|
||||
@@ -15,6 +16,10 @@ export class Reader {
|
||||
constructor(public source: Source) {}
|
||||
|
||||
requestSlice(start: number, length: number): MaybePromise<FileSlice | null> {
|
||||
if (this.source._disposed) {
|
||||
throw new InputDisposedError();
|
||||
}
|
||||
|
||||
if (this.fileSize !== null && start + length > this.fileSize) {
|
||||
return null;
|
||||
}
|
||||
@@ -40,6 +45,10 @@ export class Reader {
|
||||
}
|
||||
|
||||
requestSliceRange(start: number, minLength: number, maxLength: number): MaybePromise<FileSlice | null> {
|
||||
if (this.source._disposed) {
|
||||
throw new InputDisposedError();
|
||||
}
|
||||
|
||||
if (this.fileSize !== null) {
|
||||
return this.requestSlice(
|
||||
start,
|
||||
|
||||
Reference in New Issue
Block a user