41 lines
1.1 KiB
TypeScript
41 lines
1.1 KiB
TypeScript
//uint8转string
|
|
function Uint8ArrayToString(fileData:Uint8Array){
|
|
var dataString = "";
|
|
for (var i = 0; i < fileData.length; i++) {
|
|
dataString += String.fromCharCode(fileData[i]);
|
|
}
|
|
|
|
return dataString
|
|
|
|
}
|
|
|
|
//string 转uint8
|
|
function StringToUint8Array(str:string):Uint8Array{
|
|
var arr = [];
|
|
for (var i = 0, j = str.length; i < j; ++i) {
|
|
arr.push(str.charCodeAt(i));
|
|
}
|
|
|
|
var tmpUint8Array = new Uint8Array(arr);
|
|
return tmpUint8Array
|
|
}
|
|
|
|
function deepCopy(obj:any): any {
|
|
const copy = Object.create(Object.getPrototypeOf(obj))
|
|
var keys = Object.getOwnPropertyNames(obj)
|
|
keys.forEach(key => {
|
|
let descriptor = Object.getOwnPropertyDescriptor(obj,key)
|
|
if(descriptor)
|
|
{
|
|
if(Object.prototype.toString.call(descriptor.value)=="[object Object]")
|
|
{
|
|
descriptor.value = deepCopy(descriptor.value)
|
|
}
|
|
Object.defineProperty(copy,key,descriptor)
|
|
}
|
|
|
|
})
|
|
return copy
|
|
}
|
|
|
|
export {Uint8ArrayToString,StringToUint8Array,deepCopy} |