Skip to content

What is the proper way to read a number (int) from a binary file? #9652

Answered by caspervonb
elgs asked this question in Q&A
Discussion options

You must be logged in to vote

but Deno.read doesn't provide a parameter for how many bytes to read.

It does, it can only read up to N bytes where the number of bytes is the byteLength of the TypedArray passed in.

  • Seek to the offset,
  • Pass an Uint8Array with a byteLength of 4 to Deno.read
  • Use a DataView and call getInt32(0) to read that back as i32 (getUint32 for u32).

If you have any more questions you can find us in the #help channel on Discord https://discord.gg/bpHe9MVB

Or if you prefer the forum format, please use the Discussions tab next time for general Q&A as the issue tracker is meant for bugs 👍

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by kitsonk
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #9647 on March 02, 2021 20:26.