首页 > 编程语言 > 详细

[JavaScript]使用ArrayBuffer和Blob编辑二进制流

时间:2017-01-26 12:20:22      阅读:497      评论:0      收藏:0      [点我收藏+]

Blob()构造方法返回一个新的Blob对象. 内容是包含参数array的二进制字节流.

语法

var aBlob = new Blob( array, options );

参数

  • array is an Array of ArrayBuffer, ArrayBufferView, Blob, DOMString objects, or a mix of any of such objects, that will be put inside the Blob. DOMStrings are encoded as UTF-8.
  • options is an optional BlobPropertyBag dictionary which may specify the following two attributes:
    • type, with a default value of "", that represents the MIME type of the content of the array that will be put in the blob.
    • endings, with a default value of "transparent", that specifies how strings containing the line ending character \n are to be written out. It is one of the two values: "native", meaning that line ending characters are changed to match host OS filesystem convention, or "transparent", meaning that endings are stored in the blob without change.
var buffer = new ArrayBuffer(2);
var int8View = new Int8Array(buffer);
int8View[0] = 170;
int8View[1] = 254;

var blob = new Blob([int8View, event.target.result]);

 此段代码创建了一个2字节的二进制数10101010和11111110,并且把它追加到了event.target.result字节流的头部

[JavaScript]使用ArrayBuffer和Blob编辑二进制流

原文:http://www.cnblogs.com/yiyide266/p/6351446.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!