arraybuffer

How do you download a PDF from an API in angular2 RC5?

梦想的初衷 提交于 2019-12-06 03:53:57
This previous question had some good work arounds: Angular 2 download PDF from API and Display it in View but now that RC5 is out we can use arrayBuffer(). I can't seem to get anywhere with this. How do I go from this to a nice pdf blob: return this._authHttp.get(this.fileUrl+id) .map((res:Response) => res.arrayBuffer()) .subscribe( data => { console.log(data); var blob = new Blob([data], {type: 'application/pdf'}); console.log(blob); saveAs(blob, "testData.pdf"); }, err => console.error(err), () => console.log('done') ); data ends up being twice the size I would expect. Any ideas what I'm

Uint16Array to Uint8Array

吃可爱长大的小学妹 提交于 2019-12-05 23:09:33
I have a basic question. Say I have a Uint16Array and I have number 4 in it. data_16=new Uint16Array([4]); Now I have a length 1 and byteLength 2; how do i convert this to Uint8Array. I do not want to create a new view. data_8 = new Uint8Array(data_16) If I do this I get array length 1 and byteLength 1. This is not what I want. I need to stretch that 16 bit value in 16array into 8 bit values so that 8bit array so it would end up with 2 values int 8 bit array. I can just create a funtion which converts with shif and to all that stuff. But Can it be done with Array manipulation only? You can use

js将4个字节型字符串转为Float

一个人想着一个人 提交于 2019-12-05 22:09:57
function convertFloat(byteStr) { var buffer = str2ArrayBuffer(byteStr, 4); var dataView = new DataView(buffer, 0, 4); return dataView.getFloat32(0); } // 字符串转为ArrayBuffer对象,参数为字符串 function str2ArrayBuffer(str, len) { var buf = new ArrayBuffer(len); var bufView = new Uint8Array(buf); for (var i = 0, strLen = str.length; i < strLen; i++) { bufView[i] = parseInt(str.substr(i * 2, 2), 16); } return buf; } 首先将字符串转换为 ArrayBuffer 对象数组,再根据DataView方法进行转换 来源: https://www.cnblogs.com/Wonderful-Life/p/11947165.html

js中接收和操作ArrayBuffer

和自甴很熟 提交于 2019-12-05 06:54:38
关于前段ArrayBuffer的数据处理也是最近遇到的,主要是用于接收并显示后端生成的图片流。 数据的获取: 一开始我用的时候ajax请求获取的文件流,但是js端并显示不出来该有的图片但是可以读出流,可能是接收和处理的方式造成的,若有大神用ajax请求能够正确读出ArrayBuffer的请指出。 这种方式是我成功接收并显示的方法。 数据解析 通过对应数据类型的请求,可以得到二进制数据,数据被存储在通过ArrayBuffer这个构造函数创建一个缓冲区内,取得数据后需要使用相对应的TypedArray进行解析。 类型化数组有以下几种: 名称 占用字节 描述 Int8Array 1 8位二补码有符号整数 Uint8Array 1 8位无符号整数 Uint8ClampedArray 1 8位无符号整型固定数组(数值在0~255之间) Int16Array 2 16位二补码有符号整数 Uint16Array 2 16位无符号整数 Int32Array 4 32 位二补码有符号整数 Uint32Array 4 32 位无符号整数 Float32Array 4 32 位 IEEE 浮点数 Float64Array 8 64 位 IEEE 浮点数 Int 为整型,Uint 为无符号数,Float 为浮点型,一个字节占八位,解析数据以"字节"为基础单位,无法直接读取位(不知道是不是这样

How to pass custom class instances through Web-Workers?

半世苍凉 提交于 2019-12-05 05:58:01
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 the main thread without losing its prototype methods? Like, would this be possible with ArrayBuffer ? I'm

Receiving WebSocket ArrayBuffer data in the browser - receiving string instead

安稳与你 提交于 2019-12-04 23:34:04
问题 I have a node.js server application and a browser client. Sending ArrayBuffer data browser -> server works perfectly, but server -> browser results in a string "[object ArrayBuffer]" being received. This happens in the latest versions of both Chrome and Firefox. Server: var serverPort = 9867; // dependencies var webSocketServer = require('websocket').server; var http = require('http'); var players = {}; var nextPlayerId = 0; // create http server var server = http.createServer(function

HTML页面预览表格文件内容

五迷三道 提交于 2019-12-04 23:27:35
背景简介 在将一个表格文件上传到服务器上之前,JS读取表格文件并将文件内容输出到页面中 vue项目 第三方 exceljs 安装 npm install exceljs 插件使用 github 中文文档地址 element ui 文件选择 el-upload 数据展示 el-table 代码以及说明 import Excel from 'exceljs'; // 引入exceljs // 预览表格文件 previewFile(){ let _this=this // 获取选择的文件 let file = this.file let reader = new FileReader(); // 在读取器加载资源停止进度时读取表格文件 reader.onloadend = event=>{ // arrayBuffer为加载后的资源 let arrayBuffer = reader.result; let workbook = new Excel.Workbook(); workbook.xlsx.load(arrayBuffer).then((workbook)=> { let result = '' // 只读取文档的第一个sheet页 let sheet= workbook.worksheets[0] let tableData=[] // 获取每一行的数据 sheet

Check for an instance of ArrayBufferView?

半世苍凉 提交于 2019-12-04 19:31:23
问题 Background With a bit of research I've found that, although ArrayBufferView wasn't initially exposed (through [NoInterfaceObject]) there appeared to be broad agreement that it should be, due to my described use case. Firefox Chrome Safari The initial agreement was to expose the ArrayBufferView constructor on the DOMWindow namespace, which was implemented in Safari (and still works in 6.1.1) and Chrome, but was then pulled from Chrome in favour of a static method ArrayBuffer.isView() .

Create image from ArrayBuffer in Nodejs

橙三吉。 提交于 2019-12-04 11:48:45
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? 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 and not completely supported for node.js write operations). Something along the line of this should help: all

scala 中的集合类

旧城冷巷雨未停 提交于 2019-12-04 11:27:26
集合的继承图 —— https://docs.scala-lang.org/overviews/collections/overview.html 不可变集合中一个 List: Traversable -> Iterable -> Seq -> LinerSeq -> List 可变集合中 ArrayBuffer: Traversable -> Iterable -> Seq -> IndexedSeq -> ArrayBuffer 来源: https://www.cnblogs.com/lemos/p/11858056.html