Skip to content

Instantly share code, notes, and snippets.

@vgvinay2
Created August 8, 2017 06:09
Show Gist options
  • Save vgvinay2/fee43a937c9aca2ed9b09029d4fa0bbe to your computer and use it in GitHub Desktop.
Save vgvinay2/fee43a937c9aca2ed9b09029d4fa0bbe to your computer and use it in GitHub Desktop.
File , user info and zip and Unzip program
'use strict';
var fs = require('fs');
const https = require('https');
const util = require('util');
const zlib = require('zlib');
const os = require('os');
//question 1
var fileName = 'assign3.js';
var readStream = fs.createReadStream(fileName);
readStream
.on('data', function (chunk) {
console.log('File name: ', fileName);
console.log('File size:', chunk.length);
})
.on('end', function () {
console.log('Done');
});
// question 2
var NI = os.networkInterfaces();
console.log(`IP address : ${NI.en0[1].address}`);
console.log(`Subnet MAsk : ${NI.en0[1].netmask}`);
console.log(os.userInfo());
//question 3
const input = 'Saurabh';
zlib.deflate(input, (err, buffer) => {
if (!err) {
console.log(buffer.toString('base64'));
}
});
const buffer = Buffer.from('eJwLTiwtSkzKAAAK8gLH', 'base64');
zlib.unzip(buffer, (err, buffer) => {
if (!err) {
console.log(buffer.toString());
} else {
console.log(err);
}
});
//question 4
const gzip = zlib.createGzip();
const inp = fs.createReadStream('assign3.js');
const out = fs.createWriteStream('assign3.zip');
inp.pipe(gzip).pipe(out);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment