使用 Deno 读取二进制文件
Read binary file with Deno
Deno 的文档似乎没有提到如何执行以下二进制文件读取操作:
- 从二进制文件的开头查找位置 p;
- 读取接下来的 4 个字节;
- 并将读取的内容转化为数字(32位整数);
- 您可以使用
Deno.seek
- 使用
file.read
- 使用
DataView.getInt32
const file = await Deno.open('binary.file');
const p = 100; // your position
await Deno.seek(file.rid, p, Deno.SeekMode.Start);
const buf = new Uint8Array(4); // you can read more and then access a particular slice of the buffer
const bytesRead = await file.read(buf);
// ... do whatever operation you want with buf
Deno 的文档似乎没有提到如何执行以下二进制文件读取操作:
- 从二进制文件的开头查找位置 p;
- 读取接下来的 4 个字节;
- 并将读取的内容转化为数字(32位整数);
- 您可以使用
Deno.seek
- 使用
file.read
- 使用
DataView.getInt32
const file = await Deno.open('binary.file');
const p = 100; // your position
await Deno.seek(file.rid, p, Deno.SeekMode.Start);
const buf = new Uint8Array(4); // you can read more and then access a particular slice of the buffer
const bytesRead = await file.read(buf);
// ... do whatever operation you want with buf