mirror of
https://github.com/arcodange-org/mediabunny.git
synced 2026-09-28 11:23:45 +02:00
Add NullTarget
This commit is contained in:
+1
-1
@@ -89,7 +89,7 @@ export {
|
||||
getFirstEncodableAudioCodec,
|
||||
getFirstEncodableSubtitleCodec,
|
||||
} from './encode';
|
||||
export { Target, BufferTarget, StreamTarget, StreamTargetChunk, StreamTargetOptions } from './target';
|
||||
export { Target, BufferTarget, StreamTarget, StreamTargetChunk, StreamTargetOptions, NullTarget } from './target';
|
||||
export { Rotation, AnyIterable, SetRequired, MaybePromise } from './misc';
|
||||
export {
|
||||
Source,
|
||||
|
||||
+13
-1
@@ -6,7 +6,7 @@
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
import { BufferTargetWriter, StreamTargetWriter, Writer } from './writer';
|
||||
import { BufferTargetWriter, NullTargetWriter, StreamTargetWriter, Writer } from './writer';
|
||||
import { Output } from './output';
|
||||
|
||||
/**
|
||||
@@ -104,3 +104,15 @@ export class StreamTarget extends Target {
|
||||
return new StreamTargetWriter(this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This target just discards all incoming data. It is useful for when you need an `Output` but extract data from it
|
||||
* differently, for example through format-specific callbacks (`onMoof`, `onMdat`, ...) or encoder events.
|
||||
* @public
|
||||
*/
|
||||
export class NullTarget extends Target {
|
||||
/** @internal */
|
||||
_createWriter() {
|
||||
return new NullTargetWriter();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -459,3 +459,24 @@ export class StreamTargetWriter extends Writer {
|
||||
return this.writer?.close();
|
||||
}
|
||||
}
|
||||
|
||||
export class NullTargetWriter extends Writer {
|
||||
private pos = 0;
|
||||
|
||||
write(data: Uint8Array) {
|
||||
this.maybeTrackWrites(data);
|
||||
this.pos += data.byteLength;
|
||||
}
|
||||
|
||||
getPos() {
|
||||
return this.pos;
|
||||
}
|
||||
|
||||
seek(newPos: number) {
|
||||
this.pos = newPos;
|
||||
}
|
||||
|
||||
async flush() {}
|
||||
async finalize() {}
|
||||
async close() {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user