-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemp.js
More file actions
29 lines (25 loc) · 796 Bytes
/
Copy pathtemp.js
File metadata and controls
29 lines (25 loc) · 796 Bytes
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
function readFileChunc(filename, offset, size){
return new Promise(function(resolve, reject) {
let stats = fs.statSync(filename);
let fileSizeInBytes = stats["size"];
let buffr = new Buffer.alloc(size);
let start = (offset >= 0) ? offset : fileSizeInBytes + offset;
fs.open(filename, 'r', function (err, fd) {
if (err) reject(err);
else {
fs.read(fd, buffr, 0, size, start, function (err, bytes) {
if ( err ) {
fs.close(fd, function (err) { });
reject( err );
}
else {
// Close the opened file.
fs.close(fd, function (err) { });
resolve( buffr );
}
});
}
});
//end promise
});
}