When I assign a decoded ArrayBuffer to a dom.value and then I encode it again, I do not get the same ArrayBuffer. In the following example, A is "ArrayBuffer { byteLength: 394924 }" whereas B is "ArrayBuffer { byteLength: 585517 }" ???? Why ?
Fbx is Autodesk's 3D model file format. It is binary, not text. I want to load the model in a previewer before it gets uploaded, just locally on the client web browser site.
html
<input id="fileUploadInput" type="file" accept=".fbx"/>
Javascript
let _handleFileSelect = function ( event ) {
let reader = new FileReader();
let files = {... event.target.files};
let file = files[0];
reader.readAsArrayBuffer(file);
reader.onload = (function(reader) {
return function() {
let fbxBuffer = reader.result;
console.log("A", fbxBuffer);
let dec = new TextDecoder();
document.getElementById('fbxFileInput').value = dec.decode(fbxBuffer);
let v = document.getElementById('fbxFileInput').value;
let enc = new TextEncoder();
console.log('B', (enc.encode(v)).buffer);
}
}
var multipleFilesInputElem = document.getElementById( 'fileUploadInput' );
multipleFilesInputElem.addEventListener( 'change' , _handleFileSelect, false);
The question can be summarized as follows: "Why A and B are not the same?"
console.log('A', fbxBuffer);
console.log('B', (new TextEncoder().encode(new TextDecoder().decode(fbxBuffer))).buffer);
Some ArrayBuffer values are not the same but some are !
