1

I have been trying to get a Float64Array to work with an array buffer but node will just not have it. When I do this....

   var ab = new ArrayBuffer(buffer.length);

   var view = new Uint8Array(ab);

   console.log(view.length);//prints 3204

But when I do this...

var ab = new ArrayBuffer(buffer.length);

var view = new Float64Array(ab);

console.log(view.length);//prints nothing

I have also tried...

var view = new Float64Array(ab,0,buffer.length);

And still doesn't work.

Can anybody shed a light on why I cant access this 64 bit array? The buffer was just read from a file which is meant to be 64 bit array of floating point numbers. I just need to get access to it.

2
  • I just tried something like that in Node 0.10.25 and it worked fine. What's the value of buffer.length? (oh; 3200 duhh) Commented Jul 2, 2015 at 16:41
  • actually the size was 3204 which is what was causing the problem. Commented Jul 2, 2015 at 17:19

1 Answer 1

1

Okay I just realised my unit testing framework was swallowing an exception which told me that the length of the buffer that goes into Float64Array must be a multiple of 8. But the file I am reading obviously has a header or something!

So I adjusted the size and it works.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.