-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathfile-reader.js
More file actions
44 lines (35 loc) · 1.06 KB
/
file-reader.js
File metadata and controls
44 lines (35 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
'use-strict';
const fs = require('fs');
module.exports = exports = {};
exports.readSingleFile = function(file, callback) {
fs.readFile(file, function(err, data) {
if(err) return callback(err);
var buffer = new Buffer(data);
var hexData = buffer.toString('hex', 0, 8);
return callback(null, hexData);
});
};
var paths = [
`${__dirname}/../data/one.txt`,
`${__dirname}/../data/two.txt`,
`${__dirname}/../data/three.txt`
];
exports.readAllFiles = function(pathArray, callback) {
var results = [];
fs.readFile(pathArray[0], function(err, data){
if(err) return callback(err);
results.push(data.toString('hex', 0, 8));
fs.readFile(pathArray[1], function(err, data){
if(err) return callback(err);
results.push(data.toString('hex', 0, 8));
fs.readFile(pathArray[2], function(err, data){
if(err) return callback(err);
results.push(data.toString('hex', 0, 8));
callback(null, results);
});
});
});
};
// exports.readAllFiles(paths, function(err, data){
// console.log('data', data);
// });