Skip to content

Commit

Permalink
Merge pull request #48 from 2youyou2/master
Browse files Browse the repository at this point in the history
support load binary file
  • Loading branch information
pandamicro committed Oct 10, 2018
2 parents f2dc6f9 + f350f9e commit c31bb8d
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion wechatgame/libs/wx-downloader.js
Expand Up @@ -29,6 +29,10 @@ var non_text_format = [
'js','png','jpg','bmp','jpeg','gif','ico','tiff','webp','image','pvr','etc','mp3','ogg','wav','m4a','font','eot','ttf','woff','svg','ttc'
];

var binary_format = [
'bin'
];

const REGEX = /^\w+:\/\/.*/;

// has sub domain
Expand Down Expand Up @@ -190,9 +194,18 @@ function nextPipe(item, callback) {

function readText (item, callback) {
var url = item.url;
var encodingFormat = 'utf8';
for (var i = 0; i < binary_format.length; i++) {
if (url.endsWith(binary_format[i])) {
// read as ArrayBuffer
encodingFormat = '';
break;
}
}

fs.readFile({
filePath: url,
encoding: 'utf8',
encoding: encodingFormat,
success: function (res) {
item.states[cc.loader.downloader.id] = cc.Pipeline.ItemState.COMPLETE;
callback(null, res.data);
Expand Down

0 comments on commit c31bb8d

Please sign in to comment.