arraybuffer

Accessing ArrayBuffer from PHP $_POST after xmlHTTPrequest send()

我只是一个虾纸丫 提交于 2019-12-07 13:00:17
问题 I'm following the tuitions on XMLHttpRequest 2 from : https://developer.mozilla.org/en/DOM/XMLHttpRequest/Sending_and_Receiving_Binary_Data and http://www.html5rocks.com/en/tutorials/file/xhr2/#toc-send-arraybuffer They're great tutorials for the client side, and here is a working extract from my script: var imagebuffer = new ArrayBuffer(size); // create the readonly memory buffer var imagedata= new Uint8Array(imagebuffer); // create a view to manipulate data // do some cool stuff with

Send ArrayBuffer with other string in one Ajax call through jQuery

与世无争的帅哥 提交于 2019-12-07 06:09:02
问题 I'm working on a project need to upload large file to server side. I decided to use HTML5 FileReader and jQuery to upload the file in chunks (ArrayBuffer). I successfully finished this task by converting the chunks into base64 string, send to backend server through jQuery.post with the data parameter in JSON format. For example $.ajax({ url: "/Home/Upload", type: "POST", data: { name: block.name, index: block.index, base64: base64 }, processData: true }); But I'd like to optimize this code

How to pass custom class instances through Web-Workers?

狂风中的少年 提交于 2019-12-07 03:04:11
问题 Since Web-Worker JSON serialize data between threads, something like this doesn't work: worker.js function Animal() {} Animal.prototype.foobar = function() {} self.onmessage = function(e) { self.postMessage({animal: new Animal()}) } main.js let worker = new Worker('worker.js') worker.onmessage = function(e) { console.log(e.data) } worker.postMessage('go!') The outcome would be a simple object with the loss of the foobar prototype method. Is it possible to transfer the custom object back to

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

こ雲淡風輕ζ 提交于 2019-12-07 00:18:09
问题 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 why it doesn't work to prevent the default browser behavior of opening the file in a new tab. Expected behavior : Download the file to the browser Actual behavior : Opens the file in a new tab Exception: Only images, pdf and browser compatible files

Egret之JSZip解析图片

拟墨画扇 提交于 2019-12-06 18:44:50
将图片加压到zip中,再使用JSZip和Egret将图片显示出来. 核心代码 : /** * 将ArrayBuffer转化为Base64 * @param {ArrayBuffer} $buffer * @param {smallLib.TYPE_IMAGE_FORMAT2ZIP} $img_ty (默认 : TYPE_IMAGE_FORMAT2ZIP = TYPE_IMAGE_FORMAT2ZIP._PNG) * @returns {string} */ public static arrayBufferToBase64( $buffer : ArrayBuffer , $img_ty : TYPE_IMAGE_FORMAT2ZIP = TYPE_IMAGE_FORMAT2ZIP._PNG) : string { let bytes : Uint8Array = new Uint8Array( $buffer ); const addFormat : Function = ( $base64 : string ) : string =>{ const $base_foramt : string = `data:image/{0};base64,${$base64}`; switch($img_ty){ case TYPE_IMAGE_FORMAT2ZIP._PNG: return

HTML5 Audio API inputBuffer.getChannelData to audio Array buffer

旧时模样 提交于 2019-12-06 15:09:26
I am making an application where I am taking mic data from the inputBuffer and I want to stream to another client and play it. However, I cannot get it wokring. My recording/capturing works fine so I will skip to relevant parts of the code function recorderProcess(e) { var left = e.inputBuffer.getChannelData(0); var convert = convertFloat32ToInt16(left); window.stream.write(convert); var src = window.URL.createObjectURL(lcm); playsound(convert); ss(socket).emit('file',convert, {size: src.size},currentgame); ss.createBlobReadStream(convert).pipe(window.stream); //ss.createReadStream(f).pipe

二进制数组-ArrayBuffer对象

元气小坏坏 提交于 2019-12-06 14:32:35
ArrayBuffer对象:存储二进制数据的一段内存,不能写/读 ,类似数组的对象 只能通过TypedArray视图/DataView视图 读/写 va buf = new ArrayBuffer(32) var dataview = new DataView(buf); dataview.getUint(8) TypedArray视图/DataView视图 区别: TypedArray视图表示一组构造函数: new Int32Array(buf) new Unit8Array(buf) 很多浏览器API用到: File API XMLHttpRequest Fetch API Canvas WebSockets 来源: https://www.cnblogs.com/yuyedaocao/p/11990160.html

How to Convert UTF8 ArrayBuffer to UTF16 JavaScript String

半腔热情 提交于 2019-12-06 06:09:14
The answers from here got me started on how to use the ArrayBuffer: Converting between strings and ArrayBuffers However, they have quite a bit of different approaches. The main one is this: function ab2str(buf) { return String.fromCharCode.apply(null, new Uint16Array(buf)); } function str2ab(str) { var buf = new ArrayBuffer(str.length*2); // 2 bytes for each char var bufView = new Uint16Array(buf); for (var i=0, strLen=str.length; i<strLen; i++) { bufView[i] = str.charCodeAt(i); } return buf; } I wanted to clarify though the difference between UTF8 and UTF16 encoding, because I'm not 100% sure

Javascript - Converting between Unicode string and ArrayBuffer

好久不见. 提交于 2019-12-06 05:54:33
问题 Does somebody know a script that is able to convert a string to a ArrayBuffer using unicode encoding? I´m creating a browser-side eqivalent of the "Buffer" of node.js. The only encoding that is left is unicode. All others are done. Thanks for your help! 回答1: I found it out by myself. Decoding: var b = new Uint8Array(str.length*2); for(var i = 0; i < b.length; i+=2){ var x = str.charCodeAt(i/2); var a = x%256; x -= a; x /= 256; b[i] = x; b[i+1] = a; } Encoding var s = ""; for(var i = 0; i <

Create image from ArrayBuffer in Nodejs

喜你入骨 提交于 2019-12-06 04:45:46
问题 I'm trying to create an image file from chunks of ArrayBuffers. all= fs.createWriteStream("out."+imgtype); for(i=0; i<end; i++){ all.write(picarray[i]); } all.end(); where picarray contains ArrayBuffer chunks. However, I get the error TypeError: Invalid non-string/buffer chunk . How can I convert ArrayBuffer chunks into an image? 回答1: Have you tried first converting it into a node.js. Buffer ? (this is the native node.js Buffer interface, whereas ArrayBuffer is the interface for the browser