【问题标题】:Read binary file with Deno使用 Deno 读取二进制文件
【发布时间】:2021-03-02 20:43:24
【问题描述】:

Deno 的文档似乎没有提到我如何执行以下二进制文件读取操作:

  1. 从二进制文件的开头寻找 p 的位置;
  2. 读取接下来的 4 个字节;
  3. 并将读取的内容转换为数字(32 位整数);

【问题讨论】:

    标签: javascript deno


    【解决方案1】:
    1. 您可以使用Deno.seek
    2. 使用file.read
    3. 使用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
    

    【讨论】:

      猜你喜欢
      • 2021-12-04
      • 2019-04-13
      • 2020-11-11
      • 2012-09-11
      • 2019-09-25
      • 2017-06-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多