2017-06-22 47 views
0

我轉換從API接收到一個文件對象字節數組文件,使用以下代碼:字節數組中Appcelerator的

var buffer = [73,109,112,111,114,116,115,32,83,121,115,116,101,....];//byte array 
var outBuffer = Ti.createBuffer({length: size }); 
     for(var i=0;i<size;i++){ 
      outBuffer[i] = buffer[i]; 
     } 
var inBufferStream = Ti.Stream.createStream({ source: outBuffer, mode: Ti.Stream.MODE_READ }); 
var outFileStream = Ti.Filesystem.getFile("test.txt").open(Ti.Filesystem.MODE_WRITE); 
var bytesWritten = Ti.Stream.writeStream(inBufferStream, outFileStream, 1024); 
outFileStream.close(); 

它需要太多的時間來創建該文件。

有沒有更好的方法在appcelerator中做到這一點?請幫忙。

回答

1

請嘗試以下代碼 -

var data = Ti.Utils.base64decode(fileString); 
var blobStream = Ti.Stream.createStream({ source: data, mode:Ti.Stream.MODE_READ }); 
var newBuffer = Ti.createBuffer({ length: data.length }); 
var bytes = blobStream.read(newBuffer); 
f.write(fileString); 

不要讓我知道如果您有任何疑問。

謝謝&關注 Jeetendra