Questions tagged [arraybuffer]

ArrayBuffer is a Javascript data type used to represent a generic, fixed-length binary data buffer.

492 questions
309
votes
25 answers

Converting between strings and ArrayBuffers

Is there a commonly accepted technique for efficiently converting JavaScript strings to ArrayBuffers and vice-versa? Specifically, I'd like to be able to write the contents of an ArrayBuffer to localStorage and to read it back.
kpozin
  • 21,813
  • 17
  • 52
  • 71
237
votes
13 answers

ArrayBuffer to base64 encoded string

I need an efficient (read native) way to convert an ArrayBuffer to a base64 string which needs to be used on a multipart post.
zaheer
  • 2,411
  • 2
  • 13
  • 4
152
votes
12 answers

Convert a binary NodeJS Buffer to JavaScript ArrayBuffer

How can I convert a NodeJS binary buffer into a JavaScript ArrayBuffer?
Drake Amara
  • 2,432
  • 3
  • 17
  • 18
126
votes
10 answers

Convert base64 string to ArrayBuffer

I need to convert a base64 encode string into an ArrayBuffer. The base64 strings are user input, they will be copy and pasted from an email, so they're not there when the page is loaded. I would like to do this in javascript without making an ajax…
Tony
  • 1,293
  • 2
  • 9
  • 5
118
votes
7 answers

How to go from Blob to ArrayBuffer

I was studying Blobs, and I noticed that when you have an ArrayBuffer, you can easily convert this to a Blob as follows: var dataView = new DataView(arrayBuffer); var blob = new Blob([dataView], { type: mimeString }); The question I have now is, is…
Jeanluca Scaljeri
  • 19,619
  • 37
  • 147
  • 259
70
votes
9 answers

Conversion between UTF-8 ArrayBuffer and String

I have an ArrayBuffer which contains a string encoded using UTF-8 and I can't find a standard way of converting such ArrayBuffer into a JS String (which I understand is encoded using UTF-16). I've seen this code in numerous places, but I fail to see…
Tom Leese
  • 17,977
  • 11
  • 41
  • 65
67
votes
5 answers

Javascript Typed Arrays and Endianness

I'm using WebGL to render a binary encoded mesh file. The binary file is written out in big-endian format (I can verify this by opening the file in a hex editor, or viewing the network traffic using fiddler). When I try to read the binary response…
Bob
  • 758
  • 1
  • 7
  • 8
47
votes
1 answer

Where to use ArrayBuffer vs typed array in JavaScript?

I am moving from Node.js to browser environment, and I am still confused over ArrayBuffer vs. typed arrays (such as Uint8Array). I am confused over where to use the typed arrays, and where to use ArrayBuffer directly. It's not hard to convert one to…
Karel Bílek
  • 32,538
  • 28
  • 83
  • 137
32
votes
3 answers

Vue/HTML/JS how to download a file to browser using the download tag

This question is different from the other answer provided, because my question is focused on VUE and if VUE also has a way to prevent the default method. This question is more specific to HTML 5 "download" along with VUE binding of the :href and…
Ricky-U
  • 355
  • 1
  • 3
  • 10
31
votes
3 answers

Appending ArrayBuffers

What is the preferable way of appending/combining ArrayBuffers? I'm receiving and parsing network packets with a variety of data structures. Incoming messages are read into ArrayBuffers. If a partial packet arrives I need to store it and wait for…
user1421750
  • 1,060
  • 1
  • 9
  • 16
28
votes
2 answers

Type 'string | ArrayBuffer' is not assignable to type 'string'

TypeScript error for reading string from FileReader Simple code to read file contents: const reader: FileReader = new FileReader(); reader.readAsText(file); reader.onload = (e) => { const csv: string = reader.result; ->…
Aragorn
  • 3,864
  • 3
  • 23
  • 35
25
votes
2 answers

How send arraybuffer as binary via Websocket?

I am working on a project with Mozilla Europe. In this project, I use websocket by Worlize (server-side) and Mozilla (client side), Node.js to try to upload files from a client to a server. My present goal is to send a arraybuffer of the file to the…
Chris
  • 259
  • 1
  • 3
  • 4
25
votes
2 answers

How do I tell the type of websocket onmessage's parameter?

Here https://developer.mozilla.org/en/WebSockets/WebSockets_reference/MessageEvent it states attribute data is of type DOMString| Blob | ArrayBuffer. How do I tell it which type I want? Or how do I know which type I get?
marc40000
  • 2,888
  • 8
  • 36
  • 60
23
votes
2 answers

How to append bytes, multi-bytes and buffer to ArrayBuffer in javascript?

Javascript ArrayBuffer or TypedArrays dont have any kind of appendByte(), appendBytes(), or appendBuffer() methods. So if I want to fill an ArrayBuffer one value at a time, how do I do it? var firstVal = 0xAB; // 1 byte var secondVal =…
codneto
  • 1,969
  • 2
  • 16
  • 28
22
votes
1 answer

Passing a JS ArrayBuffer or TypedArray to Emscripten w/o Copying

I have a very large ArrayBuffer (or TypedArray) in JavaScript that I want to pass to an emscriptened function. I'd like to pass the raw bytes without incurring a copy. If my C/C++ function takes an std::string as in: void processBuffer(std::string…
Adi Shavit
  • 15,030
  • 2
  • 55
  • 121
1
2 3
32 33