mirror of
https://github.com/denoland/deno.git
synced 2024-11-21 15:04:11 -05:00
parent
259752537f
commit
45c1737531
7 changed files with 0 additions and 220 deletions
30
cli/tsc/dts/lib.deno.ns.d.ts
vendored
30
cli/tsc/dts/lib.deno.ns.d.ts
vendored
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 },
|
||||
|
|
Loading…
Reference in a new issue