Questions tagged [arraybuffer]

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

597 questions
456
votes
29 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 then read it back.
kpozin
  • 25,691
  • 19
  • 57
  • 76
318
votes
19 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
  • 3,221
  • 2
  • 16
  • 4
215
votes
14 answers

Convert a binary NodeJS Buffer to JavaScript ArrayBuffer

How can I convert a NodeJS binary buffer into a JavaScript ArrayBuffer?
Drake Amara
  • 3,072
  • 3
  • 19
  • 18
201
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
  • 2,043
  • 2
  • 12
  • 5
144
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
  • 26,343
  • 56
  • 205
  • 333
94
votes
8 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
  • 19,309
  • 12
  • 45
  • 70
82
votes
7 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
  • 909
  • 1
  • 8
  • 8
67
votes
2 answers

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
  • 36,467
  • 31
  • 94
  • 149
66
votes
1 answer

how does axios handle blob vs arraybuffer as responseType?

I'm downloading a zip file with axios. For further processing, I need to get the "raw" data that has been downloaded. As far as I can see, in Javascript there are two types for this: Blobs and Arraybuffers. Both can be specified as responseType in…
lhk
  • 27,458
  • 30
  • 122
  • 201
54
votes
4 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
  • 592
  • 1
  • 4
  • 11
46
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
  • 5,021
  • 5
  • 26
  • 37
36
votes
4 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,200
  • 2
  • 9
  • 16
32
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
  • 2,319
  • 3
  • 24
  • 36
31
votes
3 answers

How to write a file from an ArrayBuffer in JS

I am trying to write a file uploader for Meteor framework. The principle is to split the fileon the client from an ArrayBuffer in small packets of 4096 bits that are sent to the server through a Meteor.method. The simplified code below is the part…
Karl.S
  • 2,294
  • 1
  • 26
  • 33
30
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
  • 3,167
  • 9
  • 41
  • 63
1
2 3
39 40