Skip to content

Commit

Permalink
Merge pull request #758 from Martii/Issue-678mergeArrayOfBuffersAKACh…
Browse files Browse the repository at this point in the history
…unks

Try merging the Chunks

Auto-merge
  • Loading branch information
Martii committed Oct 6, 2015
2 parents 3aa5088 + c8bd0d7 commit 97f228f
Showing 1 changed file with 23 additions and 20 deletions.
43 changes: 23 additions & 20 deletions controllers/scriptStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,42 +331,45 @@ exports.getMeta = function (aChunks, aCallback) {
// parse the blocks. But strings are memory inefficient compared
// to buffers so we only convert the least number of chunks to
// get the metadata blocks.
var i = 0;
var str = '';
var parser = null;
var rHeaderContent = null;
var headerContent = null;
var hasUserScriptHeaderContent = false;
var blocksContent = {};
var blocks = {};

for (; i < aChunks.length; ++i) {
str += aChunks[i].toString('utf8');
var buf = Buffer.concat(aChunks);
var str = buf.toString('utf8');

for (parser in parsers) {
rHeaderContent = new RegExp(
'^(?:\\uFEFF)?\/\/ ==' + parser + '==([\\s\\S]*?)^\/\/ ==\/'+ parser + '==', 'm'
);
headerContent = rHeaderContent.exec(str);
if (headerContent && headerContent[1]) {
if (parser === 'UserScript') {
hasUserScriptHeaderContent = true;
}
if (isDbg) {
console.log('> getMeta() > str');
console.log(str);
}

blocksContent[parser] = headerContent[1];
for (parser in parsers) {
rHeaderContent = new RegExp(
'^(?:\\uFEFF)?\/\/ ==' + parser + '==([\\s\\S]*?)^\/\/ ==\/'+ parser + '==', 'm'
);
headerContent = rHeaderContent.exec(str);
if (headerContent && headerContent[1]) {
if (parser === 'UserScript') {
hasUserScriptHeaderContent = true;
}

blocksContent[parser] = headerContent[1];
}
}

if (hasUserScriptHeaderContent) {
for (parser in parsers) {
if (blocksContent[parser]) {
blocks[parser] = parseMeta(parsers[parser], blocksContent[parser]);
}
if (hasUserScriptHeaderContent) {
for (parser in parsers) {
if (blocksContent[parser]) {
blocks[parser] = parseMeta(parsers[parser], blocksContent[parser]);
}
return aCallback(blocks);
}
return aCallback(blocks);
}


aCallback(null);
};

Expand Down

0 comments on commit 97f228f

Please sign in to comment.