Buffer转字符串
function ab2str(buf) {
return String.fromCharCode.apply(null, new Uint8Array(buf));
}
base64转Blod
function base64ToBlob(urlData) {
var bytes = window.atob(urlData.split(',')[1]);
//处理异常,将ascii码小于0的转换为大于0
var ab = new ArrayBuffer(bytes.length);
var ia = new Uint8Array(ab);
for (var i = 0; i < bytes.length; i++) {
ia[i] = bytes.charCodeAt(i);
}
return new Blob([ab], { type: 'image/jpeg', lastModified: new Date() });
}
字符串转Buffer很简单:
Buffer.from("hello","ASCII")
第二个参数可填其它类型
Comments | NOTHING