import {
  toBuffer
} from "./chunk-J6MN42LG.js";

// runtime/subsystems/storage/storage.memory-backend.ts
var MemoryStorageBackend = class {
  store = /* @__PURE__ */ new Map();
  async upload(key, data, contentType) {
    const buffer = await toBuffer(data);
    this.store.set(key, { data: buffer, contentType });
    return key;
  }
  async download(key) {
    const entry = this.store.get(key);
    if (!entry) {
      throw new Error(`Storage: file not found: ${key}`);
    }
    return entry.data;
  }
  async delete(key) {
    if (!this.store.has(key)) {
      throw new Error(`Storage: file not found: ${key}`);
    }
    this.store.delete(key);
  }
  async getUrl(key, _expiresInSeconds) {
    if (!this.store.has(key)) {
      throw new Error(`Storage: file not found: ${key}`);
    }
    return `memory://${key}`;
  }
  async exists(key) {
    return this.store.has(key);
  }
  async list(prefix) {
    const keys = Array.from(this.store.keys());
    if (prefix === void 0) return keys;
    return keys.filter((k) => k.startsWith(prefix));
  }
  async downloadStream(key) {
    const buffer = await this.download(key);
    return new ReadableStream({
      start(controller) {
        controller.enqueue(new Uint8Array(buffer));
        controller.close();
      }
    });
  }
  /** Clear all stored files. Useful for test teardown. */
  clear() {
    this.store.clear();
  }
  /** Return number of stored files. Useful for test assertions. */
  size() {
    return this.store.size;
  }
};

export {
  MemoryStorageBackend
};
//# sourceMappingURL=chunk-3SZFUTXE.js.map