haxe.io.Bytes.getData(): BytesData != ArrayBuffer
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 28/100
- Tipo di issue
- Bug
- Chiarezza
- Da chiarire
- Stato di attività
- Ferma
- Stack tecnologico
- javascript, node.js
- Ambito
- backend
Direzione di ricerca
Non è indicato alcun file sorgente né alcun test. Individua le implementazioni per browser e Node.js di haxe.io.Bytes.getData(), confronta i tipi restituiti e esamina prima gli esempi di ArrayBuffer e Buffer dell’issue. Il lavoro è completo quando il comportamento della piattaforma è chiaramente stabilito e qualsiasi modifica necessaria di coerenza o documentazione è stata coperta.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Hi! I'm not sure if that is even an issue, but it took me a while to understand the difference between the Browser based implementation and the one used by node (electron). So I figured others might run into this very specific case as well:
In a nutshell this is the actual runtime difference: Bytes.getData() returns ArrayBuffer in the browser but Buffer in node (electron):
// Browser:
haxe.io.Bytes.getData() : js.lib.ArrayBuffer
// Node (electron):
haxe.io.Bytes.getData() : js.node.Buffer
If you're interested - first the JavaScript runtime error I ran into:
Uncaught (in promise) TypeError: Failed to execute 'decodeAudioData' on 'BaseAudioContext': parameter 1 is not of type 'ArrayBuffer'.
at AudioContextWaveformVc._onArrayBuffer (AudioContextWaveformVc.hx:126)
This is my little handler causing problems where _audioContext is an AudioContext instance:
function _onArrayBuffer( arrayBuffer : ArrayBuffer ) {
_audioContext.decodeAudioData( arrayBuffer, _onDecodeAudioSuccess, _onDecodeAudioError );
}
This is my bytes receiving handler, which extracts the needed ArrayBuffer and forwards it:
function _onBytes( data : Bytes ): Void {
var arrayBuffer : ArrayBuffer = data.getData();
_onArrayBuffer( arrayBuffer );
}
So if I use Google Chrome and Http to load the bytes it works fine:
var http : Http = new Http( url );
http.onBytes = _onBytes;
http.request( true );
BUT if I use the File API to read the bytes, decoding audio throws the TypeError:
var bytes : Bytes = File.getBytes( path );
_onBytes( bytes );
After some research I figured out, that running node (electron), Bytes.getData() actually returns a js.node.Buffer instance:

So in my case I had to convert the node buffer into an array buffer, which led me to this quite old stack overflow answer:
https://stackoverflow.com/questions/8609289/convert-a-binary-nodejs-buffer-to-javascript-arraybuffer/31394257#31394257
Just in case you need that:
class BufferUtil {
public static function toArrayBuffer(buf:Buffer): ArrayBuffer {
var ab = new ArrayBuffer(buf.length);
var view = new Uint8Array(ab);
for (i in 0...buf.length) {
view[i] = buf[i];
}
return ab;
}
}
So is Bytes.getData() not consistent on all platforms?
Is this expected behaviour?
Or is this just a very rare edge case?
- Lingua principale
- Haxe
- Stelle
- 177
- Fork
- 58
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di HaxeFoundation/hxnodejs
-
readBytes throws EOFAperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 42/100
HaxeFoundation/hxnodejs#198 ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 72/100
HaxeFoundation/hxnodejs#192 · 2 commenti ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 45/100
HaxeFoundation/hxnodejs#186 · 3 commenti · 2 reazioni ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 35/100
HaxeFoundation/hxnodejs#185 · 1 commento · 1 reazione ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 45/100
HaxeFoundation/hxnodejs#184 ·
Tutte le issue di HaxeFoundation/hxnodejs
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
ranxianglei/billion-context#4720 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
melgarafael/DeskcommCRM#3421 ·
I maintainer di solito rispondono entro 1 giorno
-
Xiaomi Mimo语音识别服务异常Apertapending triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 83/100
c1overzz/dsh-bili-scroll#124 ·
I maintainer di solito rispondono entro 1 giorno
-
bug doc-audit
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
I maintainer di solito rispondono entro 1 giorno