File tree Expand file tree Collapse file tree 1 file changed +7
-5
lines changed Expand file tree Collapse file tree 1 file changed +7
-5
lines changed Original file line number Diff line number Diff line change 5
5
const fs = require ( 'fs' ) ;
6
6
const crypto = require ( 'crypto' ) ;
7
7
const gzip = require ( 'node:zlib' ) . createGzip ( ) ;
8
-
8
+ console . time ( "start" ) ;
9
9
// Encryption setup
10
10
const algorithm = 'aes-256-cbc' ; // Encryption algorithm
11
11
//hard code keys/ivs
12
12
const key = Buffer . from ( "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" , "hex" ) // 32 bytes key for AES-256
13
13
const iv = Buffer . from ( "abcdef9876543210abcdef9876543210" , "hex" ) // Initialization vector (16 bytes)
14
14
15
+ const hwm = 65000 ; //updating the value changes the speed
15
16
//read stream from a file
16
- const inp = fs . createReadStream ( '/Users/HusseinNasser/Desktop/Video.mp4' ) ;
17
+ const inp = fs . createReadStream ( '/home/hussein/large.file' , { "highWaterMark" : hwm } ) // / Users/HusseinNasser/Desktop/Video.mp4');
17
18
//write stream to a file
18
- const out = fs . createWriteStream ( '/Users/HusseinNasser/Desktop/Video.mp4.enc.gz' ) ;
19
+ const out = fs . createWriteStream ( '/home/hussein/large.file.enc.gz' , { "highWaterMark" : hwm } ) // '/ Users/HusseinNasser/Desktop/Video.mp4.enc.gz');
19
20
// Create a transform stream to handle encryption
20
21
const encryptStream = crypto . createCipheriv ( algorithm , key , iv ) ;
21
22
23
+ out . on ( "close" , ( ) => console . timeEnd ( "start" ) ) ;
24
+
22
25
//write stream to encryption
23
26
//which then becomes readable
24
27
//we write it the zip stream
25
28
//pipe it finally out to a file
26
- inp . pipe ( encryptStream ) . pipe ( gzip ) . pipe ( out )
27
-
29
+ inp . pipe ( encryptStream ) . pipe ( gzip ) . pipe ( out ) ;
28
30
You can’t perform that action at this time.
0 commit comments