typed-arrays

Difference between readAsBinaryString and readAsText using FileReader

自古美人都是妖i 提交于 2019-12-23 08:07:15
问题 So as an example, when I read the π character ( \u03C0 ) from a File using the FileReader API, I get the pi character back to me when I read it using FileReader.readAsText(blob) which is expected. But when I use FileReader.readAsBinaryString(blob) , I get the result \xcf\x80 instead, which doesn't seem to have any visible correlation with the pi character. What's going on? (This probably has something to do with the way UTF-8/16 is encoded...) 回答1: Oh well, if that's all you needed... :) CF80

How to test for equality in ArrayBuffer, DataView, and TypedArray

守給你的承諾、 提交于 2019-12-23 07:32:53
问题 Is there a way how to test if two JavaScript ArrayBuffers are equal? I would like to write test for message composing method. The only way I found is to convert the ArrayBuffer to string and then compare. Did I miss something? Following code is giving false, even if I think that it should be true: (function() { 'use strict'; /* Fill buffer with data of Verse header and user_auth * command */ var buf_pos = 0; var name_len = 6 var message_len = 4 + 1 + 1 + 1 + name_len + 1; var buf = new

How to test for equality in ArrayBuffer, DataView, and TypedArray

被刻印的时光 ゝ 提交于 2019-12-23 07:32:04
问题 Is there a way how to test if two JavaScript ArrayBuffers are equal? I would like to write test for message composing method. The only way I found is to convert the ArrayBuffer to string and then compare. Did I miss something? Following code is giving false, even if I think that it should be true: (function() { 'use strict'; /* Fill buffer with data of Verse header and user_auth * command */ var buf_pos = 0; var name_len = 6 var message_len = 4 + 1 + 1 + 1 + name_len + 1; var buf = new

nodejs conversion from buffer data to byte array

浪子不回头ぞ 提交于 2019-12-21 15:10:14
问题 I want to convert buffer data to byte array. Here's what I've tried import * as fs from 'fs'; [...] event:(data) => { fs.readFile(data, function(err, data) { var arrByte= new Uint8Array(data) var binaryData= new Blob([arrByte]) console.log(binaryData) } } I'm yet to have this work hence my post. I'd very much like to know what I'm doing that's not right. 回答1: The Buffer docs are very enlightening: Prior to the introduction of TypedArray , the JavaScript language had no mechanism for reading

nodejs conversion from buffer data to byte array

喜你入骨 提交于 2019-12-21 15:10:09
问题 I want to convert buffer data to byte array. Here's what I've tried import * as fs from 'fs'; [...] event:(data) => { fs.readFile(data, function(err, data) { var arrByte= new Uint8Array(data) var binaryData= new Blob([arrByte]) console.log(binaryData) } } I'm yet to have this work hence my post. I'd very much like to know what I'm doing that's not right. 回答1: The Buffer docs are very enlightening: Prior to the introduction of TypedArray , the JavaScript language had no mechanism for reading

Converting Float32Array to Uint8Array while Preserving IEEE 754 Representation

ⅰ亾dé卋堺 提交于 2019-12-20 06:29:14
问题 I have a float32Array from decodeAudioData method, which I want to convert it to Uint8Array while preserving the float32 IEEE 754 audio data . So far I tried, var length = float32Array.length; var emptyBuffer = new ArrayBuffer(length * 4); var view = new DataView(emptyBuffer); for (var i = 0; i < length; i++) { view.setFloat32(i * 4, float32Array[i], true); } var outputArray = new Uint8Array(length); for (var j = 0; j < length; j++) { outputArray[j] = view.getUint8(j * 4); } return

Cross-browser spec for canvas pixel data?

青春壹個敷衍的年華 提交于 2019-12-19 23:24:26
问题 Does anyone happen to know how far back the current canvas pixel-data spec goes in various browsers? And if "not that far", what the previous spec(s) were? When you call or push pixels, you get / send: ImageData data: Uint8ClampedArray width: Number height: Number But I know that it used to just be: { data: Array width: Number height: Number } So if I'm generating ImageData, how do I detect what I need to generate? Is ImageData && Uint8ClampedArray sufficient? And do I immediately fall back

Cross-browser spec for canvas pixel data?

百般思念 提交于 2019-12-19 23:23:43
问题 Does anyone happen to know how far back the current canvas pixel-data spec goes in various browsers? And if "not that far", what the previous spec(s) were? When you call or push pixels, you get / send: ImageData data: Uint8ClampedArray width: Number height: Number But I know that it used to just be: { data: Array width: Number height: Number } So if I'm generating ImageData, how do I detect what I need to generate? Is ImageData && Uint8ClampedArray sufficient? And do I immediately fall back

JavaScript typed arrays: 64-bit integers?

拟墨画扇 提交于 2019-12-18 14:10:46
问题 JavaScript typed arrays, implemented in Firefox 4 and Chrome 7, are a very efficient way of storing and working with binary data in JavaScript. However, the current implementations only provide integer views up to 32 bits per member, with Int32Array and Uint32Array . Are 64-bit integer views being planned for implementation? How can I implement 64-bit integer views? How much slower will they be? 回答1: There's no practical way to implement an Int64Array , because all numbers in JavaScript are

Why is creating a Float32Array with an offset that isn't a multiple of the element size not allowed?

萝らか妹 提交于 2019-12-18 03:17:23
问题 I'd like to read a binary file with a few 32 bit float values at byte offset 31. Unfortunately, new Float32Array(buffer, 31, 6); does not work. An offset of 32 instead of 31 works but I need 31. According to this page, offset has to be a multiple of the element size, 4 in this case. I'm interested in the reason behind this behaviour. Why does it matter where the view starts? The best workaround I found thus far has not made it into gecko yet so I can't use it. Do I realy have to cut and copy