Deno.copy
copy
-
从
src
拷贝文件至dst
,拷贝至src
的EOF
或有异常出现时结束。copy()
函数返回一个Promise
, 成功时 resolve 并返回拷贝的字节数,失败时 reject 并返回拷贝过程中的首个异常。Copies from
src
todst
until eitherEOF
is reached onsrc
or an error occurs. It resolves to the number of bytes copied or rejects with the first error encountered while copying.const source = await Deno.open("my_file.txt"); const buffer = new Deno.Buffer() const bytesCopied1 = await Deno.copy(Deno.stdout, source); const bytesCopied2 = await Deno.copy(buffer, source);
因为
copy()
函数在读到EOF
时停止,所以不会将EOF
视为异常(区别于read()
函数)。Because
copy()
is defined to read fromsrc
untilEOF
, it does not treat anEOF
fromread()
as an error to be reported.
参数
- ##### dst: [Writer](interfaces/deno.writer.html)
需要拷贝至的目标位置
The destination to copy to
- ##### src: [Reader](interfaces/deno.reader.html)
拷贝的源位置
The source to copy from