From 45c1737531be882947e2f62038c0b72fbac921e3 Mon Sep 17 00:00:00 2001 From: Asher Gomez Date: Tue, 3 Sep 2024 18:35:54 +1000 Subject: [PATCH] BREAKING(io): remove `Deno.iter[Sync]()` (#25346) Towards #22079 --- cli/tsc/dts/lib.deno.ns.d.ts | 30 ------ ext/io/12_io.js | 44 -------- runtime/js/90_deno_ns.js | 2 - runtime/js/99_main.js | 4 - tests/specs/future/runtime_api/main.js | 2 - tests/specs/future/runtime_api/main.out | 2 - tests/unit/files_test.ts | 136 ------------------------ 7 files changed, 220 deletions(-) diff --git a/cli/tsc/dts/lib.deno.ns.d.ts b/cli/tsc/dts/lib.deno.ns.d.ts index 3ec06bf0b2..8d93845802 100644 --- a/cli/tsc/dts/lib.deno.ns.d.ts +++ b/cli/tsc/dts/lib.deno.ns.d.ts @@ -1863,36 +1863,6 @@ declare namespace Deno { options?: { bufSize?: number }, ): Promise; - /** - * Turns a Reader, `r`, into an async iterator. - * - * @deprecated This will be removed in Deno 2.0. See the - * {@link https://docs.deno.com/runtime/manual/advanced/migrate_deprecations | Deno 1.x to 2.x Migration Guide} - * for migration instructions. - * - * @category I/O - */ - export function iter( - r: Reader, - options?: { bufSize?: number }, - ): AsyncIterableIterator; - - /** - * Turns a ReaderSync, `r`, into an iterator. - * - * @deprecated This will be removed in Deno 2.0. See the - * {@link https://docs.deno.com/runtime/manual/advanced/migrate_deprecations | Deno 1.x to 2.x Migration Guide} - * for migration instructions. - * - * @category I/O - */ - export function iterSync( - r: ReaderSync, - options?: { - bufSize?: number; - }, - ): IterableIterator; - /** Open a file and resolve to an instance of {@linkcode Deno.FsFile}. The * file does not need to previously exist if using the `create` or `createNew` * open options. The caller may have the resulting file automatically closed diff --git a/ext/io/12_io.js b/ext/io/12_io.js index 5c31c279b1..6e95a9bca5 100644 --- a/ext/io/12_io.js +++ b/ext/io/12_io.js @@ -64,48 +64,6 @@ async function copy( return n; } -async function* iter( - r, - options, -) { - internals.warnOnDeprecatedApi( - "Deno.iter()", - new Error().stack, - "Use `ReadableStream` instead.", - ); - const bufSize = options?.bufSize ?? DEFAULT_BUFFER_SIZE; - const b = new Uint8Array(bufSize); - while (true) { - const result = await r.read(b); - if (result === null) { - break; - } - - yield TypedArrayPrototypeSubarray(b, 0, result); - } -} - -function* iterSync( - r, - options, -) { - internals.warnOnDeprecatedApi( - "Deno.iterSync()", - new Error().stack, - "Use `ReadableStream` instead.", - ); - const bufSize = options?.bufSize ?? DEFAULT_BUFFER_SIZE; - const b = new Uint8Array(bufSize); - while (true) { - const result = r.readSync(b); - if (result === null) { - break; - } - - yield TypedArrayPrototypeSubarray(b, 0, result); - } -} - function readSync(rid, buffer) { if (buffer.length === 0) return 0; const nread = core.readSync(rid, buffer); @@ -338,8 +296,6 @@ const stderr = new Stderr(); export { copy, - iter, - iterSync, read, readAll, readAllSync, diff --git a/runtime/js/90_deno_ns.js b/runtime/js/90_deno_ns.js index a958108a96..0fb9273bc3 100644 --- a/runtime/js/90_deno_ns.js +++ b/runtime/js/90_deno_ns.js @@ -104,8 +104,6 @@ const denoNs = { writeAll: buffer.writeAll, writeAllSync: buffer.writeAllSync, copy: io.copy, - iter: io.iter, - iterSync: io.iterSync, SeekMode: io.SeekMode, read(rid, buffer) { internals.warnOnDeprecatedApi( diff --git a/runtime/js/99_main.js b/runtime/js/99_main.js index 17b1e20d82..e0fb86a3f0 100644 --- a/runtime/js/99_main.js +++ b/runtime/js/99_main.js @@ -825,8 +825,6 @@ function bootstrapMainRuntime(runtimeOptions, warmup = false) { delete Deno.FsFile.prototype.rid; delete Deno.funlock; delete Deno.funlockSync; - delete Deno.iter; - delete Deno.iterSync; delete Deno.readAll; delete Deno.readAllSync; delete Deno.read; @@ -1007,8 +1005,6 @@ function bootstrapWorkerRuntime( delete Deno.FsFile.prototype.rid; delete Deno.funlock; delete Deno.funlockSync; - delete Deno.iter; - delete Deno.iterSync; delete Deno.readAll; delete Deno.readAllSync; delete Deno.read; diff --git a/tests/specs/future/runtime_api/main.js b/tests/specs/future/runtime_api/main.js index 503b6e5fbd..0c03dab335 100644 --- a/tests/specs/future/runtime_api/main.js +++ b/tests/specs/future/runtime_api/main.js @@ -14,8 +14,6 @@ console.log( ); console.log("Deno.funlock is", Deno.funlock); console.log("Deno.funlockSync is", Deno.funlockSync); -console.log("Deno.iter is", Deno.iter); -console.log("Deno.iterSync is", Deno.iterSync); console.log("Deno.readAll is", Deno.readAll); console.log("Deno.readAllSync is", Deno.readAllSync); console.log("Deno.read is", Deno.read); diff --git a/tests/specs/future/runtime_api/main.out b/tests/specs/future/runtime_api/main.out index eca1c3741f..f04a0b4e94 100644 --- a/tests/specs/future/runtime_api/main.out +++ b/tests/specs/future/runtime_api/main.out @@ -11,8 +11,6 @@ Deno.flockSync is undefined Deno.FsFile.prototype.rid is undefined Deno.funlock is undefined Deno.funlockSync is undefined -Deno.iter is undefined -Deno.iterSync is undefined Deno.readAll is undefined Deno.readAllSync is undefined Deno.read is undefined diff --git a/tests/unit/files_test.ts b/tests/unit/files_test.ts index 71c5a4561b..fb45e3ad6c 100644 --- a/tests/unit/files_test.ts +++ b/tests/unit/files_test.ts @@ -33,142 +33,6 @@ Deno.test( }, ); -Deno.test( - { ignore: DENO_FUTURE, permissions: { read: true } }, - async function filesIter() { - const filename = "tests/testdata/assets/hello.txt"; - using file = await Deno.open(filename); - - let totalSize = 0; - for await (const buf of Deno.iter(file)) { - totalSize += buf.byteLength; - } - - assertEquals(totalSize, 12); - }, -); - -Deno.test( - { ignore: DENO_FUTURE, permissions: { read: true } }, - async function filesIterCustomBufSize() { - const filename = "tests/testdata/assets/hello.txt"; - using file = await Deno.open(filename); - - let totalSize = 0; - let iterations = 0; - for await (const buf of Deno.iter(file, { bufSize: 6 })) { - totalSize += buf.byteLength; - iterations += 1; - } - - assertEquals(totalSize, 12); - assertEquals(iterations, 2); - }, -); - -Deno.test( - { ignore: DENO_FUTURE, permissions: { read: true } }, - function filesIterSync() { - const filename = "tests/testdata/assets/hello.txt"; - using file = Deno.openSync(filename); - - let totalSize = 0; - for (const buf of Deno.iterSync(file)) { - totalSize += buf.byteLength; - } - - assertEquals(totalSize, 12); - }, -); - -Deno.test( - { ignore: DENO_FUTURE, permissions: { read: true } }, - function filesIterSyncCustomBufSize() { - const filename = "tests/testdata/assets/hello.txt"; - using file = Deno.openSync(filename); - - let totalSize = 0; - let iterations = 0; - for (const buf of Deno.iterSync(file, { bufSize: 6 })) { - totalSize += buf.byteLength; - iterations += 1; - } - - assertEquals(totalSize, 12); - assertEquals(iterations, 2); - }, -); - -Deno.test({ ignore: DENO_FUTURE }, async function readerIter() { - // ref: https://github.com/denoland/deno/issues/2330 - const encoder = new TextEncoder(); - - class TestReader implements Deno.Reader { - #offset = 0; - #buf: Uint8Array; - - constructor(s: string) { - this.#buf = new Uint8Array(encoder.encode(s)); - } - - read(p: Uint8Array): Promise { - const n = Math.min(p.byteLength, this.#buf.byteLength - this.#offset); - p.set(this.#buf.slice(this.#offset, this.#offset + n)); - this.#offset += n; - - if (n === 0) { - return Promise.resolve(null); - } - - return Promise.resolve(n); - } - } - - const reader = new TestReader("hello world!"); - - let totalSize = 0; - for await (const buf of Deno.iter(reader)) { - totalSize += buf.byteLength; - } - - assertEquals(totalSize, 12); -}); - -Deno.test({ ignore: DENO_FUTURE }, async function readerIterSync() { - // ref: https://github.com/denoland/deno/issues/2330 - const encoder = new TextEncoder(); - - class TestReader implements Deno.ReaderSync { - #offset = 0; - #buf: Uint8Array; - - constructor(s: string) { - this.#buf = new Uint8Array(encoder.encode(s)); - } - - readSync(p: Uint8Array): number | null { - const n = Math.min(p.byteLength, this.#buf.byteLength - this.#offset); - p.set(this.#buf.slice(this.#offset, this.#offset + n)); - this.#offset += n; - - if (n === 0) { - return null; - } - - return n; - } - } - - const reader = new TestReader("hello world!"); - - let totalSize = 0; - for await (const buf of Deno.iterSync(reader)) { - totalSize += buf.byteLength; - } - - assertEquals(totalSize, 12); -}); - Deno.test( { permissions: { read: true, write: true },