-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.js
More file actions
35 lines (30 loc) · 787 Bytes
/
client.js
File metadata and controls
35 lines (30 loc) · 787 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
30
31
32
33
34
35
const http = require('http');
const { basename } = require('path');
const { createGzip } = require('zlib');
const { createReadStream, stat } = require('fs');
const filePath = process.argv[2];
const req = (stats) => {
return http.request({
method: 'POST',
hostname: '127.0.0.1',
port: 9292,
path: `/${stats.fileName}/${stats.size}`
}, (res) => {
res.on('data', (response) => {
console.log(JSON.parse(response.toString()));
});
});
};
const stream = () => {
stat(filePath, (error, stats) => {
if (error) {
throw error;
}
stats.fileName = basename(filePath);
const fileStream = createReadStream(filePath)
.pipe(createGzip({ level: 9 }))
.pipe(req(stats));
fileStream.on('close', () => {});
});
};
stream();