Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
'use strict';
const fs = require ('fs');
const Future = require ('fluture');
const exit0 = require ('./common/exit0');
const exit1 = require ('./common/exit1');
const join = require ('./common/join');
const S = require ('./common/sanctuary');
// readFile :: String -> Future Error String
const readFile = S.flip (Future.encaseN2 (fs.readFile)) ({encoding: 'utf8'});
// readFilePar :: String -> ConcurrentFuture Error String
const readFilePar = S.compose (Future.Par) (readFile);
// concatFiles :: (String -> String) -> Future Error String
const concatFiles = path =>
S.pipe ([path, // :: String
readFile, // :: Future Error String
S.map (S.lines), // :: Future Error (Array String)
S.map (S.map (path)), // :: Future Error (Array String)
S.map (S.traverse (Future.Par) (readFilePar)), // :: Future Error (ConcurrentFuture Error (Array String))
S.chain (Future.seq), // :: Future Error (Array String)
S.map (S.joinWith (''))]) // :: Future Error String
('index.txt');
return function (path, options = {}) {
options.version = options.version || this.version
const encased = Future.encaseN2(method.bind(this))
return encased(path, options)
}
}
'use strict';
const {Stream} = require ('../..');
const Future = require ('fluture');
const fs = require ('fs');
const path = require ('path');
const access = Future.encaseN2 (fs.access);
module.exports = req => Future.do (function* () {
const file = path.resolve (__dirname, '..', path.basename (req.query.file));
if (path.extname (req.query.file) !== '.jpeg') {
yield Future.reject (new Error ('You can only load JPEGs'));
}
yield (access (file, fs.constants.R_OK)).mapRej (
_ => new Error ('No read access to the requested file')
);
return Stream (200,
path.extname (req.query.file),
fs.createReadStream (file));
});