mediabunny 1.22.0 → 1.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,3 +1,6 @@
1
+ > [!NOTE]
2
+ > I'm on vacation until 18 October, so expect slow or no replies to issues during that time. 🏖️
3
+
1
4
  # Mediabunny - JavaScript media toolkit
2
5
 
3
6
  [![](https://img.shields.io/npm/v/mediabunny)](https://www.npmjs.com/package/mediabunny)
@@ -77,6 +77,7 @@ var Mediabunny = (() => {
77
77
  EncodedVideoPacketSource: () => EncodedVideoPacketSource,
78
78
  FLAC: () => FLAC,
79
79
  FilePathSource: () => FilePathSource,
80
+ FilePathTarget: () => FilePathTarget,
80
81
  FlacInputFormat: () => FlacInputFormat,
81
82
  FlacOutputFormat: () => FlacOutputFormat,
82
83
  Input: () => Input,
@@ -15655,6 +15656,7 @@ var Mediabunny = (() => {
15655
15656
  this.workers = [];
15656
15657
  this.cache = [];
15657
15658
  this.currentCacheSize = 0;
15659
+ this.disposed = false;
15658
15660
  }
15659
15661
  read(innerStart, innerEnd) {
15660
15662
  assert(this.fileSize !== null);
@@ -15831,6 +15833,9 @@ var Mediabunny = (() => {
15831
15833
  }
15832
15834
  /** Called by a worker when it has read some data. */
15833
15835
  supplyWorkerData(worker, bytes2) {
15836
+ if (this.disposed) {
15837
+ return;
15838
+ }
15834
15839
  const start = worker.currentPos;
15835
15840
  const end = start + bytes2.length;
15836
15841
  this.insertIntoCache({
@@ -15962,6 +15967,7 @@ var Mediabunny = (() => {
15962
15967
  }
15963
15968
  this.workers.length = 0;
15964
15969
  this.cache.length = 0;
15970
+ this.disposed = true;
15965
15971
  }
15966
15972
  };
15967
15973
 
@@ -18494,6 +18500,8 @@ var Mediabunny = (() => {
18494
18500
  };
18495
18501
 
18496
18502
  // src/target.ts
18503
+ var nodeAlias2 = __toESM(require_node(), 1);
18504
+ var node2 = typeof nodeAlias2 !== "undefined" ? nodeAlias2 : void 0;
18497
18505
  var Target = class {
18498
18506
  constructor() {
18499
18507
  /** @internal */
@@ -18542,6 +18550,44 @@ var Mediabunny = (() => {
18542
18550
  return new StreamTargetWriter(this);
18543
18551
  }
18544
18552
  };
18553
+ var FilePathTarget = class extends Target {
18554
+ /** Creates a new {@link FilePathTarget} that writes to the file at the specified file path. */
18555
+ constructor(filePath, options = {}) {
18556
+ if (typeof filePath !== "string") {
18557
+ throw new TypeError("filePath must be a string.");
18558
+ }
18559
+ if (!options || typeof options !== "object") {
18560
+ throw new TypeError("options must be an object.");
18561
+ }
18562
+ super();
18563
+ /** @internal */
18564
+ this._fileHandle = null;
18565
+ const writable = new WritableStream({
18566
+ start: async () => {
18567
+ this._fileHandle = await node2.fs.open(filePath, "w");
18568
+ },
18569
+ write: async (chunk) => {
18570
+ assert(this._fileHandle);
18571
+ await this._fileHandle.write(chunk.data, 0, chunk.data.byteLength, chunk.position);
18572
+ },
18573
+ close: async () => {
18574
+ if (this._fileHandle) {
18575
+ await this._fileHandle.close();
18576
+ this._fileHandle = null;
18577
+ }
18578
+ }
18579
+ });
18580
+ this._streamTarget = new StreamTarget(writable, {
18581
+ chunked: true,
18582
+ ...options
18583
+ });
18584
+ this._streamTarget._output = this._output;
18585
+ }
18586
+ /** @internal */
18587
+ _createWriter() {
18588
+ return this._streamTarget._createWriter();
18589
+ }
18590
+ };
18545
18591
  var NullTarget = class extends Target {
18546
18592
  /** @internal */
18547
18593
  _createWriter() {