mirror of
https://github.com/denoland/deno.git
synced 2024-12-22 15:24:46 -05:00
chore(runtime): deprecate Deno.copy
(#11369)
This commit is contained in:
parent
00484d24ba
commit
51e0bfda3c
10 changed files with 29 additions and 15 deletions
2
.github/workflows/ci.yml
vendored
2
.github/workflows/ci.yml
vendored
|
@ -90,7 +90,7 @@ jobs:
|
||||||
- name: Install Deno
|
- name: Install Deno
|
||||||
if: matrix.kind == 'lint'
|
if: matrix.kind == 'lint'
|
||||||
run: |
|
run: |
|
||||||
curl -fsSL https://deno.land/x/install/install.sh | sh -s v1.7.2
|
curl -fsSL https://deno.land/x/install/install.sh | sh -s v1.11.3
|
||||||
echo "$HOME/.deno/bin" >> $GITHUB_PATH
|
echo "$HOME/.deno/bin" >> $GITHUB_PATH
|
||||||
|
|
||||||
- name: Install Python
|
- name: Install Python
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
|
||||||
// Used for benchmarking Deno's tcp proxy performance.
|
// Used for benchmarking Deno's tcp proxy performance.
|
||||||
|
import { copy } from "../../test_util/std/io/util.ts";
|
||||||
|
|
||||||
const addr = Deno.args[0] || "127.0.0.1:4500";
|
const addr = Deno.args[0] || "127.0.0.1:4500";
|
||||||
const originAddr = Deno.args[1] || "127.0.0.1:4501";
|
const originAddr = Deno.args[1] || "127.0.0.1:4501";
|
||||||
|
|
||||||
|
@ -14,7 +16,7 @@ async function handle(conn: Deno.Conn): Promise<void> {
|
||||||
port: Number(originPort),
|
port: Number(originPort),
|
||||||
});
|
});
|
||||||
try {
|
try {
|
||||||
await Promise.all([Deno.copy(conn, origin), Deno.copy(origin, conn)]);
|
await Promise.all([copy(conn, origin), copy(origin, conn)]);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (
|
if (
|
||||||
!(e instanceof Deno.errors.BrokenPipe) &&
|
!(e instanceof Deno.errors.BrokenPipe) &&
|
||||||
|
|
6
cli/dts/lib.deno.ns.d.ts
vendored
6
cli/dts/lib.deno.ns.d.ts
vendored
|
@ -421,7 +421,11 @@ declare namespace Deno {
|
||||||
seekSync(offset: number, whence: SeekMode): number;
|
seekSync(offset: number, whence: SeekMode): number;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Copies from `src` to `dst` until either EOF (`null`) is read from `src` or
|
/**
|
||||||
|
* @deprecated Use `copy` from https://deno.land/std/io/util.ts instead.
|
||||||
|
* `Deno.copy` will be removed in Deno 2.0.
|
||||||
|
*
|
||||||
|
* Copies from `src` to `dst` until either EOF (`null`) is read from `src` or
|
||||||
* an error occurs. It resolves to the number of bytes copied or rejects with
|
* an error occurs. It resolves to the number of bytes copied or rejects with
|
||||||
* the first error encountered while copying.
|
* the first error encountered while copying.
|
||||||
*
|
*
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
|
import { copy } from "../../test_util/std/io/util.ts";
|
||||||
async function main(): Promise<void> {
|
async function main(): Promise<void> {
|
||||||
for (let i = 1; i < Deno.args.length; i++) {
|
for (let i = 1; i < Deno.args.length; i++) {
|
||||||
const filename = Deno.args[i];
|
const filename = Deno.args[i];
|
||||||
const file = await Deno.open(filename);
|
const file = await Deno.open(filename);
|
||||||
await Deno.copy(file, Deno.stdout);
|
await copy(file, Deno.stdout);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
|
import { copy } from "../../test_util/std/io/util.ts";
|
||||||
const addr = Deno.args[0] || "0.0.0.0:4544";
|
const addr = Deno.args[0] || "0.0.0.0:4544";
|
||||||
const [hostname, port] = addr.split(":");
|
const [hostname, port] = addr.split(":");
|
||||||
const listener = Deno.listen({ hostname, port: Number(port) });
|
const listener = Deno.listen({ hostname, port: Number(port) });
|
||||||
console.log("listening on", addr);
|
console.log("listening on", addr);
|
||||||
listener.accept().then(
|
listener.accept().then(
|
||||||
async (conn): Promise<void> => {
|
async (conn): Promise<void> => {
|
||||||
console.log("received bytes:", await Deno.copy(conn, conn));
|
console.log("received bytes:", await copy(conn, conn));
|
||||||
conn.close();
|
conn.close();
|
||||||
listener.close();
|
listener.close();
|
||||||
},
|
},
|
||||||
|
|
|
@ -8,6 +8,7 @@ import {
|
||||||
assertThrowsAsync,
|
assertThrowsAsync,
|
||||||
unitTest,
|
unitTest,
|
||||||
} from "./test_util.ts";
|
} from "./test_util.ts";
|
||||||
|
import { copy } from "../../../test_util/std/io/util.ts";
|
||||||
|
|
||||||
unitTest(function filesStdioFileDescriptors(): void {
|
unitTest(function filesStdioFileDescriptors(): void {
|
||||||
assertEquals(Deno.stdin.rid, 0);
|
assertEquals(Deno.stdin.rid, 0);
|
||||||
|
@ -21,7 +22,7 @@ unitTest({ perms: { read: true } }, async function filesCopyToStdout(): Promise<
|
||||||
const filename = "cli/tests/fixture.json";
|
const filename = "cli/tests/fixture.json";
|
||||||
const file = await Deno.open(filename);
|
const file = await Deno.open(filename);
|
||||||
assert(file.rid > 2);
|
assert(file.rid > 2);
|
||||||
const bytesWritten = await Deno.copy(file, Deno.stdout);
|
const bytesWritten = await copy(file, Deno.stdout);
|
||||||
const fileSize = Deno.statSync(filename).size;
|
const fileSize = Deno.statSync(filename).size;
|
||||||
assertEquals(bytesWritten, fileSize);
|
assertEquals(bytesWritten, fileSize);
|
||||||
file.close();
|
file.close();
|
||||||
|
|
|
@ -4,8 +4,9 @@
|
||||||
|
|
||||||
- Listening for TCP port connections with
|
- Listening for TCP port connections with
|
||||||
[Deno.listen](https://doc.deno.land/builtin/stable#Deno.listen).
|
[Deno.listen](https://doc.deno.land/builtin/stable#Deno.listen).
|
||||||
- Use [Deno.copy](https://doc.deno.land/builtin/stable#Deno.copy) to take
|
- Use
|
||||||
inbound data and redirect it to be outbound data.
|
[copy](https://doc.deno.land/https/deno.land/std@$STD_VERSION/io/util.ts#copy)
|
||||||
|
to take inbound data and redirect it to be outbound data.
|
||||||
|
|
||||||
## Example
|
## Example
|
||||||
|
|
||||||
|
@ -16,10 +17,11 @@ returns to the client anything it sends.
|
||||||
/**
|
/**
|
||||||
* echo_server.ts
|
* echo_server.ts
|
||||||
*/
|
*/
|
||||||
|
import { copy } from "https://deno.land/std@$STD_VERSION/io/util.ts";
|
||||||
const listener = Deno.listen({ port: 8080 });
|
const listener = Deno.listen({ port: 8080 });
|
||||||
console.log("listening on 0.0.0.0:8080");
|
console.log("listening on 0.0.0.0:8080");
|
||||||
for await (const conn of listener) {
|
for await (const conn of listener) {
|
||||||
Deno.copy(conn, conn).finally(() => conn.close());
|
copy(conn, conn).finally(() => conn.close());
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -7,8 +7,8 @@
|
||||||
command line arguments.
|
command line arguments.
|
||||||
- [Deno.open](https://doc.deno.land/builtin/stable#Deno.open) is used to get a
|
- [Deno.open](https://doc.deno.land/builtin/stable#Deno.open) is used to get a
|
||||||
handle to a file.
|
handle to a file.
|
||||||
- [Deno.copy](https://doc.deno.land/builtin/stable#Deno.copy) is used to
|
- [copy](https://doc.deno.land/https/deno.land/std@$STD_VERSION/io/util.ts#copy)
|
||||||
transfer data from the file to the output stream.
|
is used to transfer data from the file to the output stream.
|
||||||
- Files should be closed when you are finished with them
|
- Files should be closed when you are finished with them
|
||||||
- Modules can be run directly from remote URLs.
|
- Modules can be run directly from remote URLs.
|
||||||
|
|
||||||
|
@ -21,9 +21,10 @@ is opened, and printed to stdout (e.g. the console).
|
||||||
/**
|
/**
|
||||||
* cat.ts
|
* cat.ts
|
||||||
*/
|
*/
|
||||||
|
import { copy } from "https://deno.land/std@$STD_VERSION/io/util.ts";
|
||||||
for (const filename of Deno.args) {
|
for (const filename of Deno.args) {
|
||||||
const file = await Deno.open(filename);
|
const file = await Deno.open(filename);
|
||||||
await Deno.copy(file, Deno.stdout);
|
await copy(file, Deno.stdout);
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
|
@ -86,10 +86,11 @@ In this program each command-line argument is assumed to be a filename, the file
|
||||||
is opened, and printed to stdout.
|
is opened, and printed to stdout.
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
|
import { copy } from "https://deno.land/std@$STD_VERSION/io/util.ts";
|
||||||
const filenames = Deno.args;
|
const filenames = Deno.args;
|
||||||
for (const filename of filenames) {
|
for (const filename of filenames) {
|
||||||
const file = await Deno.open(filename);
|
const file = await Deno.open(filename);
|
||||||
await Deno.copy(file, Deno.stdout);
|
await copy(file, Deno.stdout);
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
@ -111,12 +112,13 @@ This is an example of a server which accepts connections on port 8080, and
|
||||||
returns to the client anything it sends.
|
returns to the client anything it sends.
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
|
import { copy } from "https://deno.land/std@$STD_VERSION/io/util.ts";
|
||||||
const hostname = "0.0.0.0";
|
const hostname = "0.0.0.0";
|
||||||
const port = 8080;
|
const port = 8080;
|
||||||
const listener = Deno.listen({ hostname, port });
|
const listener = Deno.listen({ hostname, port });
|
||||||
console.log(`Listening on ${hostname}:${port}`);
|
console.log(`Listening on ${hostname}:${port}`);
|
||||||
for await (const conn of listener) {
|
for await (const conn of listener) {
|
||||||
Deno.copy(conn, conn);
|
copy(conn, conn);
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 8467929052737f634eb8842a960093c686ae3b9b
|
Subproject commit 81314bcab8b5dc2fef85ec65f8588cab17063378
|
Loading…
Reference in a new issue