2013-05-13 41 views
1

我用這個方法編碼的MP3文件爲Base64在節點的JS bin文件MP3:解碼使用節點的js

encodebase64 = function(mp3file){ 
var bitmap = fs.readFileSync(mp3file); 
var encodedstring = new Buffer(bitmap).toString('base64'); 
fs.writeFileSync('encodedfile.bin', encodedstring);} 

,然後再次我希望構造從Base64的bin文件的MP3文件,但創建的文件缺少一些標題,所以顯然存在解碼問題。 解碼功能是:

decodebase64 = function(encodedfile){ 
var bitmap = fs.readFileSync(encodedfile); 
var decodedString = new Buffer(bitmap, 'base64'); 
fs.writeFileSync('decodedfile.mp3', decodedString);} 

我想知道,如果有人可以幫助 感謝。

回答

0

也許這是編碼參數的問題。詳細信息請參見this answer。解碼時嘗試使用utf8以查看是否有差別。你在哪些平臺上運行你的代碼?

+0

我也嘗試過使用utf8,但仍然無法使用!它會創建解碼後的MP3文件,但解碼MP3文件的大小比原始文件大,並且由於MISSING HEADERS錯誤而無法運行!我正在Webinos平臺上運行代碼! – user2377882 2013-05-13 14:53:10