Skip to content

Commit 33f6b94

Browse files
authored
fix(seed) unmarshal buffer value
If the seed file contains a serialized Buffer value, it will be unmarshalled before seeding. Fixes #94
1 parent 5e12d93 commit 33f6b94

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/seeder.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,27 @@ function getSeedsAtLocation(location) {
101101

102102
// Ensure the output is an array
103103
if (Array.isArray(result)) {
104-
return result;
104+
return _.forEach(result, unmarshalBuffer);
105105
} else {
106-
return [ result ];
106+
return [ unmarshalBuffer(result) ];
107107
}
108108
}
109109

110+
/**
111+
* Transform all selerialized Buffer value in a Buffer value inside a json object
112+
*
113+
* @param {json} json with serialized Buffer value.
114+
* @return {json} json with Buffer object.
115+
*/
116+
function unmarshalBuffer(json) {
117+
_.forEach(json, function(value, key) {
118+
if (value.type==='Buffer') {
119+
json[key]= new Buffer(value.data);
120+
}
121+
});
122+
return json;
123+
}
124+
110125
/**
111126
* Locates seeds given a set of files to scrape
112127
* @param {string[]} sources The filenames to scrape for seeds

0 commit comments

Comments
 (0)