mirror of
https://github.com/arcodange-org/mediabunny.git
synced 2026-09-27 19:03:46 +02:00
Add some more argument validation
This commit is contained in:
+14
-6
@@ -15,24 +15,28 @@ export abstract class Source {
|
||||
}
|
||||
|
||||
/** @public */
|
||||
export class ArrayBufferSource extends Source {
|
||||
export class BufferSource extends Source {
|
||||
/** @internal */
|
||||
_buffer: ArrayBuffer;
|
||||
_bytes: Uint8Array;
|
||||
|
||||
constructor(buffer: ArrayBuffer | Uint8Array) {
|
||||
if (!(buffer instanceof ArrayBuffer) && !(buffer instanceof Uint8Array)) {
|
||||
throw new TypeError('buffer must be an ArrayBuffer or Uint8Array.');
|
||||
}
|
||||
|
||||
constructor(buffer: ArrayBuffer) {
|
||||
super();
|
||||
|
||||
this._buffer = buffer;
|
||||
this._bytes = buffer instanceof Uint8Array ? buffer : new Uint8Array(buffer);
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
override async _read(start: number, end: number) {
|
||||
return new Uint8Array(this._buffer, start, end - start);
|
||||
return this._bytes.subarray(start, end);
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
override async _retrieveSize() {
|
||||
return this._buffer.byteLength;
|
||||
return this._bytes.byteLength;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,6 +46,10 @@ export class BlobSource extends Source {
|
||||
_blob: Blob;
|
||||
|
||||
constructor(blob: Blob) {
|
||||
if (!(blob instanceof Blob)) {
|
||||
throw new TypeError('blob must be a Blob.');
|
||||
}
|
||||
|
||||
super();
|
||||
|
||||
this._blob = blob;
|
||||
|
||||
Reference in New Issue
Block a user