// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
// This module is browser compatible.

/**
 * An abstract interface which when implemented provides an interface to read bytes into an array buffer asynchronously.
 */
export interface Reader {
  /** Reads up to `p.byteLength` bytes into `p`. It resolves to the number of
   * bytes read (`0` < `n` <= `p.byteLength`) and rejects if any error
   * encountered. Even if `read()` resolves to `n` < `p.byteLength`, it may
   * use all of `p` as scratch space during the call. If some data is
   * available but not `p.byteLength` bytes, `read()` conventionally resolves
   * to what is available instead of waiting for more.
   *
   * When `read()` encounters end-of-file condition, it resolves to EOF
   * (`null`).
   *
   * When `read()` encounters an error, it rejects with an error.
   *
   * Callers should always process the `n` > `0` bytes returned before
   * considering the EOF (`null`). Doing so correctly handles I/O errors that
   * happen after reading some bytes and also both of the allowed EOF
   * behaviors.
   *
   * Implementations should not retain a reference to `p`.
   *
   * Use iterateReader() from https://deno.land/std@$STD_VERSION/streams/iterate_reader.ts to turn a Reader into an
   * AsyncIterator.
   */
  read(p: Uint8Array): Promise<number | null>;
}

/**
 * An abstract interface which when implemented provides an interface to read bytes into an array buffer synchronously.
 */
export interface ReaderSync {
  /** Reads up to `p.byteLength` bytes into `p`. It resolves to the number
   * of bytes read (`0` < `n` <= `p.byteLength`) and rejects if any error
   * encountered. Even if `read()` returns `n` < `p.byteLength`, it may use
   * all of `p` as scratch space during the call. If some data is available
   * but not `p.byteLength` bytes, `read()` conventionally returns what is
   * available instead of waiting for more.
   *
   * When `readSync()` encounters end-of-file condition, it returns EOF
   * (`null`).
   *
   * When `readSync()` encounters an error, it throws with an error.
   *
   * Callers should always process the `n` > `0` bytes returned before
   * considering the EOF (`null`). Doing so correctly handles I/O errors that happen
   * after reading some bytes and also both of the allowed EOF behaviors.
   *
   * Implementations should not retain a reference to `p`.
   *
   * Use iterateReaderSync() from https://deno.land/std@$STD_VERSION/streams/iterate_reader.ts to turn a ReaderSync
   * into an Iterator.
   */
  readSync(p: Uint8Array): number | null;
}

/**
 * An abstract interface which when implemented provides an interface to write bytes from an array buffer to a file/resource asynchronously.
 */
export interface Writer {
  /** Writes `p.byteLength` bytes from `p` to the underlying data stream. It
   * resolves to the number of bytes written from `p` (`0` <= `n` <=
   * `p.byteLength`) or reject with the error encountered that caused the
   * write to stop early. `write()` must reject with a non-null error if
   * would resolve to `n` < `p.byteLength`. `write()` must not modify the
   * slice data, even temporarily.
   *
   * Implementations should not retain a reference to `p`.
   */
  write(p: Uint8Array): Promise<number>;
}
/**
 * An abstract interface which when implemented provides an interface to write bytes from an array buffer to a file/resource synchronously.
 */
export interface WriterSync {
  /** Writes `p.byteLength` bytes from `p` to the underlying data
   * stream. It returns the number of bytes written from `p` (`0` <= `n`
   * <= `p.byteLength`) and any error encountered that caused the write to
   * stop early. `writeSync()` must throw a non-null error if it returns `n` <
   * `p.byteLength`. `writeSync()` must not modify the slice data, even
   * temporarily.
   *
   * Implementations should not retain a reference to `p`.
   */
  writeSync(p: Uint8Array): number;
}

/**
 * An abstract interface which when implemented provides an interface to close files/resources that were previously opened.
 */
export interface Closer {
  /** Closes the resource, "freeing" the backing file/resource. */
  close(): void;
}

// denoCacheMetadata={"headers":{"x-amz-cf-pop":"AMS58-P5","access-control-allow-origin":"*","x-frame-options":"DENY","date":"Sun, 08 Mar 2026 12:06:23 GMT","x-amz-replication-status":"COMPLETED","server-timing":"fetchSource;dur=5","x-amz-cf-id":"t1WcGLdOwB6-gq9rG47wWz_Mm1ekHUvYvKAkmD9dVStVQKPtFxrIyA==","referrer-policy":"strict-origin-when-cross-origin","cache-control":"public, max-age=31536000, immutable","last-modified":"Thu, 15 Feb 2024 05:02:28 GMT","server":"AmazonS3,deployd","cross-origin-resource-policy":"same-origin","x-content-type-options":"nosniff","content-type":"application/typescript; charset=utf-8","x-deno-trace-id":"ac7a39017795a9567317b3e69f311468","etag":"\"64845a999aa1b13c17be1960062012ec\"","cross-origin-embedder-policy":"same-origin","x-cache":"Hit from cloudfront","alt-svc":"h3=\":443\"; ma=86400","age":"1029002","via":"1.1 ffde4ac468ae53bebcf62edbe5888ab6.cloudfront.net (CloudFront),HTTP/2 ams.vultr.prod.deno-cluster.net","content-length":"4203","content-security-policy":"default-src 'none'; style-src 'unsafe-inline'; sandbox","vary":"Accept-Encoding, Origin","x-amz-server-side-encryption":"AES256","cross-origin-opener-policy":"same-origin","x-amz-version-id":"sW8a70KF_mdqRQs9a7NxABzKEm_.tyBA","cache-status":"deno; hit","accept-ranges":"bytes","strict-transport-security":"max-age=63072000; includeSubDomains; preload"},"url":"https://deno.land/std@0.216.0/io/types.ts","time":1774000576}