"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var File_exports = {};
__export(File_exports, {
  File: () => File,
  FileTypeError: () => FileTypeError
});
module.exports = __toCommonJS(File_exports);
var import_FilesystemError = require("./FilesystemError.js");
var import_FilesystemNode = require("./FilesystemNode.js");
/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
class File extends import_FilesystemNode.FilesystemNode {
  kind = "file";
  /**
   * Read all bytes from the file into a single buffer.
   */
  async readAllBytes() {
    const chunks = Array();
    let totalLength = 0;
    for await (const chunk of this.readBytes()) {
      chunks.push(chunk);
      totalLength += chunk.length;
    }
    if (chunks.length === 1) {
      return chunks[0];
    }
    const result = new Uint8Array(totalLength);
    let offset = 0;
    for (const chunk of chunks) {
      result.set(chunk, offset);
      offset += chunk.length;
    }
    return result;
  }
  /**
   * Read the entire file as a string.
   */
  async readAllText() {
    const chunks = Array();
    for await (const chunk of this.readText()) {
      chunks.push(chunk);
    }
    return chunks.join("");
  }
}
((File2) => {
  class Handle extends File2 {
  }
  File2.Handle = Handle;
  class Cursor {
    #position = 0;
    #max;
    constructor(max) {
      this.#max = max;
    }
    /**
     * The upper byte bound for this cursor (typically file size).
     */
    get max() {
      return this.#max;
    }
    /**
     * The current byte position in the file.
     */
    get position() {
      return this.#position;
    }
    /**
     * Move the cursor to a byte position.
     */
    seek(position) {
      this.#position = position;
    }
    /**
     * Read up to {@link length} bytes from the current position.
     *
     * Returns fewer bytes than requested at EOF.  Advances the position by the number of bytes read.
     *
     * @param copy when true, returns a new owned buffer; when false (default), returns a view of the internal
     *   buffer that is invalidated on the next read
     */
    async read(length, copy) {
      const result = await this.readAt(this.#position, length, copy);
      this.#position += result.length;
      return result;
    }
  }
  File2.Cursor = Cursor;
})(File || (File = {}));
class FileTypeError extends import_FilesystemError.FilesystemError {
}
//# sourceMappingURL=File.js.map
