Skip to content

Commit 081d25d

Browse files
authored
Merge pull request #95 from remicastaing/patch-2
fix(seed) unmarshal buffer value
2 parents b15f3ee + e8c0175 commit 081d25d

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
@@ -88,6 +88,21 @@ function fileExists(fileName) {
8888
});
8989
}
9090

91+
/**
92+
* Transform all selerialized Buffer value in a Buffer value inside a json object
93+
*
94+
* @param {json} json with serialized Buffer value.
95+
* @return {json} json with Buffer object.
96+
*/
97+
function unmarshalBuffer(json) {
98+
_.forEach(json, function(value, key) {
99+
if (value.type==="Buffer") {
100+
json[key]= new Buffer(value.data);
101+
}
102+
});
103+
return json;
104+
}
105+
91106
/**
92107
* Scrapes seed files out of a given location. This file may contain
93108
* either a simple json object, or an array of simple json objects. An array
@@ -101,9 +116,9 @@ function getSeedsAtLocation(location) {
101116

102117
// Ensure the output is an array
103118
if (Array.isArray(result)) {
104-
return result;
119+
return _.forEach(result, unmarshalBuffer);
105120
} else {
106-
return [ result ];
121+
return [ unmarshalBuffer(result) ];
107122
}
108123
}
109124

0 commit comments

Comments
 (0)