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

import { Buffer } from "./buffer.ts";

/**
 * Reader utility for strings.
 *
 * @example Usage
 * ```ts
 * import { StringReader } from "@std/io/string-reader";
 * import { assertEquals } from "@std/assert/equals";
 *
 * const data = new Uint8Array(6);
 * const r = new StringReader("abcdef");
 * const res0 = await r.read(data);
 * const res1 = await r.read(new Uint8Array(6));
 *
 * assertEquals(res0, 6);
 * assertEquals(res1, null);
 * assertEquals(new TextDecoder().decode(data), "abcdef");
 * ```
 *
 * @deprecated This will be removed in 1.0.0. Use the {@link https://developer.mozilla.org/en-US/docs/Web/API/Streams_API | Web Streams API} instead.
 */
export class StringReader extends Buffer {
  /**
   * Construct a new instance.
   *
   * @param s The string to read.
   */
  constructor(s: string) {
    super(new TextEncoder().encode(s).buffer);
  }
}

// denoCacheMetadata={"headers":{"access-control-expose-headers":"*","cache-control":"public, max-age=31536000, immutable","vary":"Origin","nel":"{\"report_to\":\"cf-nel\",\"success_fraction\":0.0,\"max_age\":604800}","date":"Tue, 28 Jul 2026 12:31:15 GMT","access-control-allow-origin":"*","server":"cloudflare","report-to":"{\"group\":\"cf-nel\",\"max_age\":604800,\"endpoints\":[{\"url\":\"https://a.nel.cloudflare.com/report/v4?s=EDxKsyoPaoahlibOR52I9WilaXbKhsiuCQodY2og3gae2UPTYEFH0CtRHiQjCXOdfzM0Ta%2B%2FOoK%2FlKyKZeMOqdiUvGDR373ES6albmbuHbQyW5E3xvDpwWQ%3D\"}]}","alt-svc":"h3=\":443\"; ma=86400","x-content-type-options":"nosniff","x-jsr-backend":"modules","content-security-policy":"default-src 'none'; script-src 'none'; style-src 'none'; img-src 'none'; font-src 'none'; connect-src 'none'; frame-src 'none'; object-src 'none'; frame-ancestors 'none'; sandbox; form-action 'none';","cf-ray":"a223e65728e27db6-LAX","etag":"\"feea4b2b08f5f3c0dc49ad125db58ca9\"","content-length":"979","set-cookie":"__cf_bm=HD7YliYWvZojrhy_TQHzVESKkfXloCfjzRrh6WzkBVQ-1785241875.0649168-1.0.1.1-C.lHRXId68FcFLmU34T12CVR2p.pfbm8aCkT80UqL66SgC8AaSVVtXQ1_md3eBpg2ZVa8PpsrfoQW5qBr4ffvigm6gfM2.W1qpgGLr_2IvgGWRFcoyX8Z6lEM_nKLSd4; HttpOnly; SameSite=None; Secure; Path=/; Domain=jsr.io; Expires=Tue, 28 Jul 2026 13:01:15 GMT","content-type":"text/typescript","x-robots-tag":"noindex","cross-origin-resource-policy":"cross-origin"},"url":"https://jsr.io/@std/io/0.224.8/string_reader.ts","time":1785241875}