Added reading and writing from file to db

parent 7ea74bef
"use strict";
const s2s = require('string-to-stream');
const fs = require('fs');
module.exports.getModelFunctions = (model, logger) => {
......@@ -37,6 +38,10 @@ module.exports.getModelFunctions = (model, logger) => {
return functions.saveStream(filename, s2s(fileContent), meta, mime)
};
functions.saveFromFile = async (filePath, fileName) => {
return functions.saveStream(fileName, fs.createReadStream(filePath))
};
functions.readStream = (id, stream) => {
return new Promise((s, r) => {
let dbStream = model.read({_id: id});
......@@ -74,6 +79,10 @@ module.exports.getModelFunctions = (model, logger) => {
});
};
functions.readToFile = async (id, filePath) => {
return functions.readStream(id, fs.createWriteStream(filePath))
};
functions.fileInfo = id => {
return model.findOne({_id: id})
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment