arraybuffer

Angular 4.3: Getting an arraybuffer with new HttpClient

本秂侑毒 提交于 2019-12-18 12:45:55
问题 I would like to change to the new HttpClient. Until now I handle file downloads the following: getXlsx (): Observable<any> { return this.http.get('api/xlsx', { responseType: ResponseContentType.ArrayBuffer, // set as ArrayBuffer instead of Json }) .map(res => downloadFile(res, 'application/xlsx', 'export.xlsx')) .catch(err => handleError(err)); } export function downloadFile(data: any, type: string, filename: string): string { const blob = new Blob([data._body], { type }); const url = window

Javascript Typed Arrays and Endianness

吃可爱长大的小学妹 提交于 2019-12-17 04:47:31
问题 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 using a Float32Array or Int32Array, the binary is interpreted as little-endian and my values are wrong: // Interpret first 32bits in buffer as an int var wrongValue = new Int32Array(binaryArrayBuffer)[0]; I can't find any references to the default

JavaScript中你所不知道的数组ArrayBuffer

好久不见. 提交于 2019-12-16 22:54:41
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 前段时间一直在研究 Web Audio API 以及语音通信相关的知识,内容侧重于音频流在 AudioContext 各个节点之间的流动情况,而现在要摸清楚音频到流底是个什么样的数据格式,所以对 ArrayBuffer 的研究就显得格外重要了。 一、Array 在内存中的堆栈模型 1. Array 的获取 Javascript 中如何产生 Array: [element0, element1, ..., elementN] new Array(element0, element1, ..., elementN) new Array(arrayLength) 直接定义,或者通过构造函数创建一个 Array,当然也可以使用其他的手段: "array".split(""); "array".match(/a|r/g); 等等,方式有很多。但是 Array 内部是个什么样的结构,恐怕很多人还不是很清楚。 2. 堆栈模型 在数组中我们可以放很多不同数据类型的数据,如: var arr = [21, "李靖", new Date(), function(){}, , null]; 上面这个数组中一次放入了 数字、字符串、对象、函数、undefined 和 null,对于上面的数据接口我们可以具象的描述下: 栈 +-----

JavaScript中你所不知道的数组ArrayBuffer

不问归期 提交于 2019-12-16 22:48:14
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 前段时间一直在研究 Web Audio API 以及语音通信相关的知识,内容侧重于音频流在 AudioContext 各个节点之间的流动情况,而现在要摸清楚音频到流底是个什么样的数据格式,所以对 ArrayBuffer 的研究就显得格外重要了。 一、Array 在内存中的堆栈模型 1. Array 的获取 Javascript 中如何产生 Array: [element0, element1, ..., elementN] new Array(element0, element1, ..., elementN) new Array(arrayLength) 直接定义,或者通过构造函数创建一个 Array,当然也可以使用其他的手段: "array".split(""); "array".match(/a|r/g); 等等,方式有很多。但是 Array 内部是个什么样的结构,恐怕很多人还不是很清楚。 2. 堆栈模型 在数组中我们可以放很多不同数据类型的数据,如: var arr = [21, "李靖", new Date(), function(){}, , null]; 上面这个数组中一次放入了 数字、字符串、对象、函数、undefined 和 null,对于上面的数据接口我们可以具象的描述下: 栈 +-----

【前端知乎系列】ArrayBuffer 和 Blob 对象

这一生的挚爱 提交于 2019-12-16 22:40:59
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 本文首发在我的【 个人博客 】 更多丰富的前端学习资料,可以查看我的 Github : 《Leo-JavaScript》 ,内容涵盖 数据结构与算法 、 HTTP 、 Hybrid 、 面试题 、 React 、 Angular 、 TypeScript 和 Webpack 等等。 点个 Star 不迷路~ ArrayBuffer 对象与 Blob 对象大家或许不太陌生,常见于文件上传操作处理(如处理图片上传预览等问题)。 那么本文将与大家深入介绍两者。 一、ArrayBuffer 对象 ArrayBuffer 对象是 ES6 才纳入正式 ECMAScript 规范,是 JavaScript 操作二进制数据 的一个接口。 ArrayBuffer 对象是以数组的语法处理二进制数据,也称二进制数组。 介绍 ArrayBuffer 对象还需介绍 TypedArray 视图和 DataView 视图,本文不具体介绍,详细可以查看阮一峰老师 《ECMAScript 6 入门 ArrayBuffer》 章节。 1. 概念介绍 ArrayBuffer 对象代表储存二进制数据的一段内存,它不能直接读写,只能通过视图( TypedArray 视图和 DataView 视图)来读写,视图的作用是以指定格式解读二进制数据。 关于

What does it mean if binary data is “4 byte single format” and how do I read it in JavaScript?

末鹿安然 提交于 2019-12-13 21:36:48
问题 I have to read a binary file which is said to be encoded 4 byte single format and never having to work with binary data, I don't know what this means. I can do this reading a file with binary data in JavaScript: d = new FileReader(); d.onload = function (e) { var i, len; // grab a "chunk" response_buffer = e.target.result.slice(0, 1024); view = new DataView(response_buffer); for (i = 0, len = response_buffer.byteLength; i < len; i += 1) { // hmhm console.log(view.getUint8(i)); } } d

imageData set in InternetExplorer

╄→гoц情女王★ 提交于 2019-12-12 13:26:10
问题 I have an arraybuffer - named MEM - larger than the canvas width*height size. And I would like to draw the arrayBuffer data to the canvas. imgData.data.set(...) should work, because imgData.data is an Uint8Array, which has the .set hethod. It works in FireFox, and Chrome, but in IE I get this error: Object doesn't support this property or method: 'set' Initializaton: var MEM = new ArrayBuffer(2*1024*1024); var canvas, ctx, imgData; var init = function() { canvas = document.getElementById(

Trim or cut audio recorded with mediarecorder JS

有些话、适合烂在心里 提交于 2019-12-12 08:14:43
问题 Requested Knowledge How to shorten (from the front) an array of audio blobs and still have playable audio. Goal I am ultimately trying to record a continuous 45 second loop of audio using the JS MediaRecorder API. The user will be able to push a button and the last 45s of audio will be saved. I can record, playback, and download a single recording just fine. Issue When I have an array called chunks of say 1000 blobs from the MediaRecorder and use chunks.slice(500, 1000) the resulting blob

base64 encoding in javascript with bit shifting

独自空忆成欢 提交于 2019-12-12 03:03:32
问题 I have the following decode/encode routine. However, the encoding is not working properly (it should be printing "CMlaKA" not "ClaKA" to the console log). I think the problem is with the bit shifting, but I cant tell where. Here is a jsfiddle to explain https://jsfiddle.net/4yfrLv9y/16/ Here is the code (routine is run at the bottom) var consoleLine = "<p class=\"console-line\"></p>"; console = { log: function (text) { $("#console-log").append($(consoleLine).html(text)); } }; var Base64 = {

Offset is outside the bounds of the DataView;at api notifyBLECharacteristicValueChanged success call

人盡茶涼 提交于 2019-12-11 22:45:19
在做微信小程序开发,向蓝牙发送信息时,遇到这样一个错误 错误解释: 数组下标越界 报错原因: 我在设置ArrayBuffer时,直接设置过少,导致在循环通过蓝牙传递信息时,造成数组下标越界。 解决办法: 方法一 ,给ArrayBuffer长度设置更长; 方法二,在循环时,获取数组的长度,确保数组长度不超过循环次数。 修改后代码: var retstring = [1,2,3]; var buffer = new ArrayBuffer(14); //设置最多保存14个字节 var dataView = new DataView(buffer); let values = 0; for (let i = 0; i < retstring .length; i++) { let str = retstring[i] + ""; if (str.length>=2){ values = str.charCodeAt();//字符转为ascii } dataView.setUint8(i, values);//向蓝牙发送命令参数 } 详细报错信息: Offset is outside the bounds of the DataView;at api notifyBLECharacteristicValueChanged success callback function