All new
alle new
This commit is contained in:
1 parent
da64472251
commit
5b20adee48
1605 files changed
+396517
-1674
No files matched your search
+56
@@ -0,0 +1,56 @@
|
||||
var path = require("path");
|
||||
var _ = require("underscore");
|
||||
|
||||
var fs = require("../lib/fs");
|
||||
var promises = require("../lib/promises");
|
||||
|
||||
exports.testPath = testPath;
|
||||
exports.testData = testData;
|
||||
exports.createFakeDocxFile = createFakeDocxFile;
|
||||
exports.createFakeFiles = createFakeFiles;
|
||||
|
||||
|
||||
function testPath(filename) {
|
||||
return path.join(__dirname, "test-data", filename);
|
||||
}
|
||||
|
||||
function testData(testDataPath) {
|
||||
var fullPath = testPath(testDataPath);
|
||||
return fs.readFile(fullPath, "utf-8");
|
||||
}
|
||||
|
||||
function createFakeDocxFile(files) {
|
||||
function exists(path) {
|
||||
return !!files[path];
|
||||
}
|
||||
|
||||
return {
|
||||
read: createRead(files),
|
||||
exists: exists
|
||||
};
|
||||
}
|
||||
|
||||
function createFakeFiles(files) {
|
||||
return {
|
||||
read: createRead(files)
|
||||
};
|
||||
}
|
||||
|
||||
function createRead(files) {
|
||||
function read(path, encoding) {
|
||||
return promises.resolve(files[path], function(buffer) {
|
||||
if (_.isString(buffer)) {
|
||||
buffer = new Buffer(buffer);
|
||||
}
|
||||
|
||||
if (!Buffer.isBuffer(buffer)) {
|
||||
return promises.reject(new Error("file was not a buffer"));
|
||||
} else if (encoding) {
|
||||
return promises.resolve(buffer.toString(encoding));
|
||||
} else {
|
||||
return promises.resolve(buffer.buffer);
|
||||
}
|
||||
});
|
||||
}
|
||||
return read;
|
||||
}
|
||||
Reference in new issue
Block a user