Skip to content

Commit f2f88af

Browse files
committed
chore: comments
1 parent 8ef1f26 commit f2f88af

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-2
lines changed

src/job-client.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -471,8 +471,8 @@ class JobClient{
471471
}
472472

473473
/**
474-
* Call the Modzy API Service that return the jobs features
475-
* @return {Object} a updated job instance
474+
* Call Modzy's API Service to return job features
475+
* @return {Object} An updated job instance
476476
* @throws {ApiError} If there is something wrong with the sevice or the call
477477
*/
478478
getFeatures(){

src/utils.js

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
const fs = require('fs');
2+
3+
function readBytes(fd, sharedBuffer) {
4+
return new Promise((resolve, reject) => {
5+
fs.read(
6+
fd,
7+
sharedBuffer,
8+
0,
9+
sharedBuffer.length,
10+
null,
11+
(err) => {
12+
if(err) { return reject(err); }
13+
resolve();
14+
}
15+
);
16+
});
17+
}
18+
19+
async function* fileToChunks(filePath, size) {
20+
const sharedBuffer = Buffer.alloc(size);
21+
const stats = fs.statSync(filePath);
22+
const fd = fs.openSync(filePath, "r");
23+
let bytesRead = 0;
24+
let end = size;
25+
for(let i = 0; i < Math.ceil(stats.size / size); i++) {
26+
await readBytes(fd, sharedBuffer);
27+
bytesRead = (i + 1) * size;
28+
if(bytesRead > stats.size) {
29+
end = size - (bytesRead - stats.size);
30+
}
31+
yield sharedBuffer.slice(0, end);
32+
}
33+
fs.closeSync(fd);
34+
}
35+
36+
async function* byteArrayToChunks(byteArray, size) {
37+
for(let i = 0; i < byteArray.length; i += size) {
38+
yield byteArray.slice(i, i+size);
39+
}
40+
}
41+
42+
module.exports = {
43+
byteArrayToChunks,
44+
fileToChunks
45+
};

0 commit comments

Comments
 (0)