mirror of
https://github.com/denoland/deno
synced 2024-08-27 12:00:17 +00:00
feat: deprecate Deno.write()
and Deno.writeSync()
(#22064)
For removal in Deno v2.
This commit is contained in:
parent
50eaeabefb
commit
a5a973e93c
|
@ -27,7 +27,7 @@ Deno.test(
|
|||
create: true,
|
||||
});
|
||||
const data = new Uint8Array(64);
|
||||
await Deno.write(file.rid, data);
|
||||
await file.write(data);
|
||||
await Deno.fdatasync(file.rid);
|
||||
assertEquals(await Deno.readFile(filename), data);
|
||||
await Deno.remove(filename);
|
||||
|
|
|
@ -13,7 +13,7 @@ Deno.test({
|
|||
create: true,
|
||||
});
|
||||
const data = new Uint8Array(64);
|
||||
await Deno.write(file.rid, data);
|
||||
await file.write(data);
|
||||
|
||||
await new Promise<void>((resolve, reject) => {
|
||||
fdatasync(file.rid, (err: Error | null) => {
|
||||
|
|
|
@ -117,13 +117,13 @@ Deno.test("tls.createServer creates a TLS server", async () => {
|
|||
assertEquals(text.replaceAll("\0", ""), "welcome!\n");
|
||||
buf.fill(0);
|
||||
|
||||
Deno.write(conn.rid, new TextEncoder().encode("hey\n"));
|
||||
await conn.write(new TextEncoder().encode("hey\n"));
|
||||
await conn.read(buf);
|
||||
text = new TextDecoder().decode(buf);
|
||||
assertEquals(text.replaceAll("\0", ""), "hey\n");
|
||||
buf.fill(0);
|
||||
|
||||
Deno.write(conn.rid, new TextEncoder().encode("goodbye\n"));
|
||||
await conn.write(new TextEncoder().encode("goodbye\n"));
|
||||
await conn.read(buf);
|
||||
text = new TextDecoder().decode(buf);
|
||||
assertEquals(text.replaceAll("\0", ""), "goodbye\n");
|
||||
|
|
16
cli/tsc/dts/lib.deno.ns.d.ts
vendored
16
cli/tsc/dts/lib.deno.ns.d.ts
vendored
|
@ -2039,6 +2039,9 @@ declare namespace Deno {
|
|||
* const bytesWritten = await Deno.write(file.rid, data); // 11
|
||||
* ```
|
||||
*
|
||||
* @deprecated Use `writer.write()` instead. {@linkcode Deno.write} will be
|
||||
* removed in Deno 2.0.
|
||||
*
|
||||
* @category I/O
|
||||
*/
|
||||
export function write(rid: number, data: Uint8Array): Promise<number>;
|
||||
|
@ -2061,6 +2064,9 @@ declare namespace Deno {
|
|||
* const bytesWritten = Deno.writeSync(file.rid, data); // 11
|
||||
* ```
|
||||
*
|
||||
* @deprecated Use `writer.writeSync()` instead. {@linkcode Deno.writeSync}
|
||||
* will be removed in Deno 2.0.
|
||||
*
|
||||
* @category I/O
|
||||
*/
|
||||
export function writeSync(rid: number, data: Uint8Array): number;
|
||||
|
@ -2074,7 +2080,7 @@ declare namespace Deno {
|
|||
* "hello.txt",
|
||||
* { read: true, write: true, truncate: true, create: true },
|
||||
* );
|
||||
* await Deno.write(file.rid, new TextEncoder().encode("Hello world"));
|
||||
* await file.write(new TextEncoder().encode("Hello world"));
|
||||
*
|
||||
* // advance cursor 6 bytes
|
||||
* const cursorPosition = await Deno.seek(file.rid, 6, Deno.SeekMode.Start);
|
||||
|
@ -2092,7 +2098,7 @@ declare namespace Deno {
|
|||
* "hello.txt",
|
||||
* { read: true, write: true, truncate: true, create: true },
|
||||
* );
|
||||
* await Deno.write(file.rid, new TextEncoder().encode("Hello world"));
|
||||
* await file.write(new TextEncoder().encode("Hello world"));
|
||||
*
|
||||
* // Seek 6 bytes from the start of the file
|
||||
* console.log(await Deno.seek(file.rid, 6, Deno.SeekMode.Start)); // "6"
|
||||
|
@ -2170,7 +2176,7 @@ declare namespace Deno {
|
|||
* "my_file.txt",
|
||||
* { read: true, write: true, create: true },
|
||||
* );
|
||||
* await Deno.write(file.rid, new TextEncoder().encode("Hello World"));
|
||||
* await file.write(new TextEncoder().encode("Hello World"));
|
||||
* await file.truncate(1);
|
||||
* await Deno.fsync(file.rid);
|
||||
* console.log(await Deno.readTextFile("my_file.txt")); // H
|
||||
|
@ -2212,7 +2218,7 @@ declare namespace Deno {
|
|||
* "my_file.txt",
|
||||
* { read: true, write: true, create: true },
|
||||
* );
|
||||
* await Deno.write(file.rid, new TextEncoder().encode("Hello World"));
|
||||
* await file.write(new TextEncoder().encode("Hello World"));
|
||||
* await Deno.fdatasync(file.rid);
|
||||
* console.log(await Deno.readTextFile("my_file.txt")); // Hello World
|
||||
* ```
|
||||
|
@ -5304,7 +5310,7 @@ declare namespace Deno {
|
|||
* "my_file.txt",
|
||||
* { read: true, write: true, create: true }
|
||||
* );
|
||||
* await Deno.write(file.rid, new TextEncoder().encode("Hello World"));
|
||||
* await file.write(new TextEncoder().encode("Hello World"));
|
||||
* await Deno.ftruncate(file.rid, 7);
|
||||
* const data = new Uint8Array(32);
|
||||
* await Deno.read(file.rid, data);
|
||||
|
|
|
@ -140,8 +140,22 @@ const denoNs = {
|
|||
);
|
||||
return io.readSync(rid, buffer);
|
||||
},
|
||||
write: io.write,
|
||||
writeSync: io.writeSync,
|
||||
write(rid, data) {
|
||||
internals.warnOnDeprecatedApi(
|
||||
"Deno.write()",
|
||||
new Error().stack,
|
||||
"Use `writer.write()` instead.",
|
||||
);
|
||||
return io.write(rid, data);
|
||||
},
|
||||
writeSync(rid, data) {
|
||||
internals.warnOnDeprecatedApi(
|
||||
"Deno.writeSync()",
|
||||
new Error().stack,
|
||||
"Use `writer.writeSync()` instead.",
|
||||
);
|
||||
return io.writeSync(rid, data);
|
||||
},
|
||||
File: fs.File,
|
||||
FsFile,
|
||||
open: fs.open,
|
||||
|
|
Loading…
Reference in a new issue