1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-21 15:04:11 -05:00

BREAKING(io): remove Deno.iter[Sync]() (#25346)

Towards #22079
This commit is contained in:
Asher Gomez 2024-09-03 18:35:54 +10:00 committed by GitHub
parent 259752537f
commit 45c1737531
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 0 additions and 220 deletions

View file

@ -1863,36 +1863,6 @@ declare namespace Deno {
options?: { bufSize?: number },
): Promise<number>;
/**
* 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<Uint8Array>;
/**
* 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<Uint8Array>;
/** 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

View file

@ -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,

View file

@ -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(

View file

@ -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;

View file

@ -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);

View file

@ -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

View file

@ -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<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 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 },