diff --git a/archive/_common.ts b/archive/_common.ts index 0f6c427b093b..ab0ddeb7e0d3 100644 --- a/archive/_common.ts +++ b/archive/_common.ts @@ -1,7 +1,7 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. import { PartialReadError } from "../io/buf_reader.ts"; -import type { Reader } from "../io/types.d.ts"; +import type { Reader } from "../io/types.ts"; export interface TarInfo { fileMode?: number; diff --git a/archive/tar.ts b/archive/tar.ts index 5544b167e4cb..b32b55aea790 100644 --- a/archive/tar.ts +++ b/archive/tar.ts @@ -35,7 +35,7 @@ import { type TarOptions, ustarStructure, } from "./_common.ts"; -import type { Reader } from "../io/types.d.ts"; +import type { Reader } from "../io/types.ts"; import { MultiReader } from "../io/multi_reader.ts"; import { Buffer } from "../io/buffer.ts"; import { assert } from "../assert/assert.ts"; diff --git a/archive/untar.ts b/archive/untar.ts index 0a597f9cd2dc..12cc2a73d212 100644 --- a/archive/untar.ts +++ b/archive/untar.ts @@ -38,7 +38,7 @@ import { ustarStructure, } from "./_common.ts"; import { readAll } from "../streams/read_all.ts"; -import type { Reader } from "../io/types.d.ts"; +import type { Reader } from "../io/types.ts"; /** * Extend TarMeta with the `linkName` property so that readers can access diff --git a/io/_test_common.ts b/io/_test_common.ts index 7c2fb2fa23cf..a3eca231aa7a 100644 --- a/io/_test_common.ts +++ b/io/_test_common.ts @@ -1,6 +1,6 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -import type { Reader } from "./types.d.ts"; +import type { Reader } from "./types.ts"; export const MIN_READ_BUFFER_SIZE = 16; export const bufsizes: number[] = [ diff --git a/io/buf_reader.ts b/io/buf_reader.ts index 57b95fa1d8d2..1121091456d6 100644 --- a/io/buf_reader.ts +++ b/io/buf_reader.ts @@ -8,7 +8,7 @@ import { assert } from "../assert/assert.ts"; import { copy } from "../bytes/copy.ts"; -import type { Reader } from "./types.d.ts"; +import type { Reader } from "./types.ts"; const DEFAULT_BUF_SIZE = 4096; const MIN_BUF_SIZE = 16; diff --git a/io/buf_reader_test.ts b/io/buf_reader_test.ts index aabda41fd42e..36d5d5cf94da 100644 --- a/io/buf_reader_test.ts +++ b/io/buf_reader_test.ts @@ -7,7 +7,7 @@ import { BufferFullError, BufReader, PartialReadError } from "./buf_reader.ts"; import { StringReader } from "./string_reader.ts"; import { bufsizes, MIN_READ_BUFFER_SIZE } from "./_test_common.ts"; import { Buffer } from "./buffer.ts"; -import type { Reader } from "./types.d.ts"; +import type { Reader } from "./types.ts"; import { copy } from "../bytes/copy.ts"; /** OneByteReader returns a Reader that implements diff --git a/io/buf_writer.ts b/io/buf_writer.ts index 108f15ce105e..e10f4ddda443 100644 --- a/io/buf_writer.ts +++ b/io/buf_writer.ts @@ -2,7 +2,7 @@ // This module is browser compatible. import { copy } from "../bytes/copy.ts"; -import type { Writer, WriterSync } from "./types.d.ts"; +import type { Writer, WriterSync } from "./types.ts"; const DEFAULT_BUF_SIZE = 4096; diff --git a/io/buf_writer_test.ts b/io/buf_writer_test.ts index 6a7da9469110..fc4d273a3a68 100644 --- a/io/buf_writer_test.ts +++ b/io/buf_writer_test.ts @@ -7,7 +7,7 @@ import { BufWriter, BufWriterSync } from "./buf_writer.ts"; import { Buffer } from "./buffer.ts"; import { StringWriter } from "./string_writer.ts"; import { bufsizes } from "./_test_common.ts"; -import type { Writer, WriterSync } from "./types.d.ts"; +import type { Writer, WriterSync } from "./types.ts"; Deno.test("bufioWriter", async function () { const data = new Uint8Array(8192); diff --git a/io/buffer.ts b/io/buffer.ts index 3d95667d5b5a..94b95cb32ac0 100644 --- a/io/buffer.ts +++ b/io/buffer.ts @@ -3,7 +3,7 @@ import { assert } from "../assert/assert.ts"; import { copy } from "../bytes/copy.ts"; -import type { Reader, ReaderSync } from "./types.d.ts"; +import type { Reader, ReaderSync } from "./types.ts"; // MIN_READ is the minimum ArrayBuffer size passed to a read call by // buffer.ReadFrom. As long as the Buffer has at least MIN_READ bytes beyond diff --git a/io/copy_n.ts b/io/copy_n.ts index e50e02618858..28bf0de9323d 100644 --- a/io/copy_n.ts +++ b/io/copy_n.ts @@ -2,7 +2,7 @@ // This module is browser compatible. import { assert } from "../assert/assert.ts"; -import type { Reader, Writer } from "./types.d.ts"; +import type { Reader, Writer } from "./types.ts"; const DEFAULT_BUFFER_SIZE = 32 * 1024; diff --git a/io/limited_reader.ts b/io/limited_reader.ts index c9c553bd385b..84292111ed66 100644 --- a/io/limited_reader.ts +++ b/io/limited_reader.ts @@ -7,7 +7,7 @@ * `read` returns `null` when `limit` <= `0` or * when the underlying `reader` returns `null`. */ -import type { Reader } from "./types.d.ts"; +import type { Reader } from "./types.ts"; /** * @deprecated (will be removed after 1.0.0) Use the [Web Streams API]{@link https://developer.mozilla.org/en-US/docs/Web/API/Streams_API} instead. diff --git a/io/multi_reader.ts b/io/multi_reader.ts index b8ed9d0d744a..2fe5ec8eef0b 100644 --- a/io/multi_reader.ts +++ b/io/multi_reader.ts @@ -1,7 +1,7 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. // This module is browser compatible. -import type { Reader } from "./types.d.ts"; +import type { Reader } from "./types.ts"; /** * Reader utility for combining multiple readers diff --git a/io/read_delim.ts b/io/read_delim.ts index 4b7d0d0f2086..a8b712080f95 100644 --- a/io/read_delim.ts +++ b/io/read_delim.ts @@ -2,7 +2,7 @@ // This module is browser compatible. import { concat } from "../bytes/concat.ts"; -import type { Reader } from "./types.d.ts"; +import type { Reader } from "./types.ts"; /** Generate longest proper prefix which is also suffix array. */ function createLPS(pat: Uint8Array): Uint8Array { diff --git a/io/read_lines.ts b/io/read_lines.ts index af4c24e165db..b1c1b0f7af0e 100644 --- a/io/read_lines.ts +++ b/io/read_lines.ts @@ -1,7 +1,7 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. // This module is browser compatible. -import { type Reader } from "./types.d.ts"; +import { type Reader } from "./types.ts"; import { BufReader } from "./buf_reader.ts"; import { concat } from "../bytes/concat.ts"; diff --git a/io/read_range.ts b/io/read_range.ts index 1d29d0328853..1feb0ddb0f28 100644 --- a/io/read_range.ts +++ b/io/read_range.ts @@ -2,7 +2,7 @@ import { copy as copyBytes } from "../bytes/copy.ts"; import { assert } from "../assert/assert.ts"; -import type { Reader, ReaderSync } from "./types.d.ts"; +import type { Reader, ReaderSync } from "./types.ts"; const DEFAULT_BUFFER_SIZE = 32 * 1024; diff --git a/io/read_range_test.ts b/io/read_range_test.ts index 970f0cf0a66f..cbe567cbccb2 100644 --- a/io/read_range_test.ts +++ b/io/read_range_test.ts @@ -8,7 +8,7 @@ import { assertThrows, } from "../assert/mod.ts"; import { readRange, readRangeSync } from "./read_range.ts"; -import type { Closer, Reader, ReaderSync } from "./types.d.ts"; +import type { Closer, Reader, ReaderSync } from "./types.ts"; // N controls how many iterations of certain checks are performed. const N = 100; diff --git a/io/read_string_delim.ts b/io/read_string_delim.ts index 059ad9470280..64d7cf7197e1 100644 --- a/io/read_string_delim.ts +++ b/io/read_string_delim.ts @@ -1,7 +1,7 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. // This module is browser compatible. -import { type Reader } from "./types.d.ts"; +import { type Reader } from "./types.ts"; import { readDelim } from "./read_delim.ts"; /** diff --git a/io/string_writer.ts b/io/string_writer.ts index c9f4b176ab89..4b6698dec8e6 100644 --- a/io/string_writer.ts +++ b/io/string_writer.ts @@ -1,7 +1,7 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. // This module is browser compatible. -import type { Writer, WriterSync } from "./types.d.ts"; +import type { Writer, WriterSync } from "./types.ts"; const decoder = new TextDecoder(); diff --git a/io/types.d.ts b/io/types.d.ts index f84430a61857..b132a5cd4490 100644 --- a/io/types.d.ts +++ b/io/types.d.ts @@ -4,15 +4,13 @@ /** * See the Contributing > Types section in the README for an explanation of this file. * - * @deprecate (will be removed in 1.0.0) Use the - * [Streams API]{@linkcode https://developer.mozilla.org/en-US/docs/Web/API/Streams_API} - * instead. + * @deprecated (will be removed in 0.214.0) Import from {@link https://deno.land/std/io/types.ts} instead. */ /** * An abstract interface which when implemented provides an interface to read bytes into an array buffer asynchronously. * - * @deprecated (will be removed in 1.0.0) Use {@linkcode ReadableStream} instead. + * @deprecated (will be removed in 0.214.0) Import from {@link https://deno.land/std/io/types.ts} instead. */ export interface Reader { /** Reads up to `p.byteLength` bytes into `p`. It resolves to the number of @@ -43,7 +41,7 @@ export interface Reader { /** * An abstract interface which when implemented provides an interface to read bytes into an array buffer synchronously. * - * @deprecated (will be removed in 1.0.0) Use {@linkcode ReadableStream} instead. + * @deprecated (will be removed in 0.214.0) Import from {@link https://deno.land/std/io/types.ts} instead. */ export interface ReaderSync { /** Reads up to `p.byteLength` bytes into `p`. It resolves to the number @@ -73,7 +71,7 @@ export interface ReaderSync { /** * An abstract interface which when implemented provides an interface to write bytes from an array buffer to a file/resource asynchronously. * - * @deprecated (will be removed in 1.0.0) Use {@linkcode WritableStream} instead. + * @deprecated (will be removed in 0.214.0) Import from {@link https://deno.land/std/io/types.ts} instead. */ export interface Writer { /** Writes `p.byteLength` bytes from `p` to the underlying data stream. It @@ -90,7 +88,7 @@ export interface Writer { /** * An abstract interface which when implemented provides an interface to write bytes from an array buffer to a file/resource synchronously. * - * @deprecated (will be removed in 1.0.0) Use {@linkcode WritableStream} instead. + * @deprecated (will be removed in 0.214.0) Import from {@link https://deno.land/std/io/types.ts} instead. */ export interface WriterSync { /** Writes `p.byteLength` bytes from `p` to the underlying data @@ -108,7 +106,7 @@ export interface WriterSync { /** * An abstract interface which when implemented provides an interface to close files/resources that were previously opened. * - * @deprecated (will be removed in 1.0.0) Use {@linkcode ReadableStream} and {@linkcode WritableStream} instead. + * @deprecated (will be removed in 0.214.0) Import from {@link https://deno.land/std/io/types.ts} instead. */ export interface Closer { /** Closes the resource, "freeing" the backing file/resource. */ diff --git a/io/types.ts b/io/types.ts new file mode 100644 index 000000000000..f84430a61857 --- /dev/null +++ b/io/types.ts @@ -0,0 +1,116 @@ +// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +// This module is browser compatible. + +/** + * See the Contributing > Types section in the README for an explanation of this file. + * + * @deprecate (will be removed in 1.0.0) Use the + * [Streams API]{@linkcode https://developer.mozilla.org/en-US/docs/Web/API/Streams_API} + * instead. + */ + +/** + * An abstract interface which when implemented provides an interface to read bytes into an array buffer asynchronously. + * + * @deprecated (will be removed in 1.0.0) Use {@linkcode ReadableStream} instead. + */ +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; +} + +/** + * An abstract interface which when implemented provides an interface to read bytes into an array buffer synchronously. + * + * @deprecated (will be removed in 1.0.0) Use {@linkcode ReadableStream} instead. + */ +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. + * + * @deprecated (will be removed in 1.0.0) Use {@linkcode WritableStream} instead. + */ +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; +} +/** + * An abstract interface which when implemented provides an interface to write bytes from an array buffer to a file/resource synchronously. + * + * @deprecated (will be removed in 1.0.0) Use {@linkcode WritableStream} instead. + */ +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. + * + * @deprecated (will be removed in 1.0.0) Use {@linkcode ReadableStream} and {@linkcode WritableStream} instead. + */ +export interface Closer { + /** Closes the resource, "freeing" the backing file/resource. */ + close(): void; +} diff --git a/streams/copy.ts b/streams/copy.ts index bf80c05707dc..fff276655297 100644 --- a/streams/copy.ts +++ b/streams/copy.ts @@ -2,7 +2,7 @@ // This module is browser compatible. import { DEFAULT_BUFFER_SIZE } from "./_common.ts"; -import type { Reader, Writer } from "../io/types.d.ts"; +import type { Reader, Writer } from "../io/types.ts"; /** * Copies from `src` to `dst` until either EOF (`null`) is read from `src` or diff --git a/streams/iterate_reader.ts b/streams/iterate_reader.ts index a47593214034..f97a8de46dfa 100644 --- a/streams/iterate_reader.ts +++ b/streams/iterate_reader.ts @@ -2,7 +2,7 @@ // This module is browser compatible. import { DEFAULT_BUFFER_SIZE } from "./_common.ts"; -import type { Reader, ReaderSync } from "../io/types.d.ts"; +import type { Reader, ReaderSync } from "../io/types.ts"; export type { Reader, ReaderSync }; diff --git a/streams/iterate_reader_test.ts b/streams/iterate_reader_test.ts index 3f001a4477f4..130327ee3843 100644 --- a/streams/iterate_reader_test.ts +++ b/streams/iterate_reader_test.ts @@ -4,7 +4,7 @@ import { assertEquals } from "../assert/mod.ts"; import { iterateReader, iterateReaderSync } from "./iterate_reader.ts"; import { readerFromIterable } from "./reader_from_iterable.ts"; import { delay } from "../async/delay.ts"; -import type { Reader, ReaderSync } from "../io/types.d.ts"; +import type { Reader, ReaderSync } from "../io/types.ts"; Deno.test("iterateReader", async () => { // ref: https://github.com/denoland/deno/issues/2330 diff --git a/streams/read_all.ts b/streams/read_all.ts index 6d40f2307614..42c6a2cd3e65 100644 --- a/streams/read_all.ts +++ b/streams/read_all.ts @@ -2,7 +2,7 @@ // This module is browser compatible. import { Buffer } from "../io/buffer.ts"; -import type { Reader, ReaderSync } from "../io/types.d.ts"; +import type { Reader, ReaderSync } from "../io/types.ts"; /** * Read {@linkcode Reader} `r` until EOF (`null`) and resolve to the content as diff --git a/streams/readable_stream_from_reader.ts b/streams/readable_stream_from_reader.ts index d3139bb7eab5..e825823db634 100644 --- a/streams/readable_stream_from_reader.ts +++ b/streams/readable_stream_from_reader.ts @@ -2,7 +2,7 @@ // This module is browser compatible. import { DEFAULT_CHUNK_SIZE } from "./_common.ts"; -import type { Closer, Reader } from "../io/types.d.ts"; +import type { Closer, Reader } from "../io/types.ts"; export type { Closer }; function isCloser(value: unknown): value is Closer { diff --git a/streams/readable_stream_from_reader_test.ts b/streams/readable_stream_from_reader_test.ts index 7f0adc13116f..5b712a223bf4 100644 --- a/streams/readable_stream_from_reader_test.ts +++ b/streams/readable_stream_from_reader_test.ts @@ -5,7 +5,7 @@ import { readableStreamFromReader } from "./readable_stream_from_reader.ts"; import { Buffer } from "../io/buffer.ts"; import { concat } from "../bytes/concat.ts"; import { copy } from "../bytes/copy.ts"; -import type { Closer, Reader } from "../io/types.d.ts"; +import type { Closer, Reader } from "../io/types.ts"; class MockReaderCloser implements Reader, Closer { chunks: Uint8Array[] = []; diff --git a/streams/reader_from_iterable.ts b/streams/reader_from_iterable.ts index 82f06f031c95..a79355d894c0 100644 --- a/streams/reader_from_iterable.ts +++ b/streams/reader_from_iterable.ts @@ -3,7 +3,7 @@ import { Buffer } from "../io/buffer.ts"; import { writeAll } from "./write_all.ts"; -import { Reader } from "../io/types.d.ts"; +import { Reader } from "../io/types.ts"; /** * Create a {@linkcode Reader} from an iterable of {@linkcode Uint8Array}s. diff --git a/streams/reader_from_stream_reader.ts b/streams/reader_from_stream_reader.ts index 56988664aa46..617dfc032dad 100644 --- a/streams/reader_from_stream_reader.ts +++ b/streams/reader_from_stream_reader.ts @@ -3,7 +3,7 @@ import { Buffer } from "../io/buffer.ts"; import { writeAll } from "./write_all.ts"; -import type { Reader } from "../io/types.d.ts"; +import type { Reader } from "../io/types.ts"; /** * Create a {@linkcode Reader} from a {@linkcode ReadableStreamDefaultReader}. diff --git a/streams/writable_stream_from_writer.ts b/streams/writable_stream_from_writer.ts index d072d1c3cd2c..b82ed7f8a320 100644 --- a/streams/writable_stream_from_writer.ts +++ b/streams/writable_stream_from_writer.ts @@ -2,7 +2,7 @@ // This module is browser compatible. import { writeAll } from "./write_all.ts"; -import type { Closer, Writer } from "../io/types.d.ts"; +import type { Closer, Writer } from "../io/types.ts"; function isCloser(value: unknown): value is Closer { return typeof value === "object" && value !== null && value !== undefined && diff --git a/streams/writable_stream_from_writer_test.ts b/streams/writable_stream_from_writer_test.ts index 31cca9aff4b0..555db1b60220 100644 --- a/streams/writable_stream_from_writer_test.ts +++ b/streams/writable_stream_from_writer_test.ts @@ -2,7 +2,7 @@ import { assertEquals } from "../assert/mod.ts"; import { writableStreamFromWriter } from "./writable_stream_from_writer.ts"; -import type { Closer, Writer } from "../io/types.d.ts"; +import type { Closer, Writer } from "../io/types.ts"; class MockWriterCloser implements Writer, Closer { chunks: Uint8Array[] = []; diff --git a/streams/write_all.ts b/streams/write_all.ts index 2b27a0290117..20a10759878c 100644 --- a/streams/write_all.ts +++ b/streams/write_all.ts @@ -1,7 +1,7 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. // This module is browser compatible. -import type { Writer, WriterSync } from "../io/types.d.ts"; +import type { Writer, WriterSync } from "../io/types.ts"; export type { Writer, WriterSync }; /** diff --git a/streams/writer_from_stream_writer.ts b/streams/writer_from_stream_writer.ts index 9592d94677e2..cfa284e5a18a 100644 --- a/streams/writer_from_stream_writer.ts +++ b/streams/writer_from_stream_writer.ts @@ -1,7 +1,7 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. // This module is browser compatible. -import type { Writer } from "../io/types.d.ts"; +import type { Writer } from "../io/types.ts"; /** * Create a {@linkcode Writer} from a {@linkcode WritableStreamDefaultWriter}.