-
Notifications
You must be signed in to change notification settings - Fork 0
/
shownfo.js
30 lines (30 loc) · 990 Bytes
/
shownfo.js
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
const http = require('http');
const iconv = require('iconv-lite');
function shownfo(url, callback) {
if (url.length > 0) {
http.get(url, function(resp) {
const statusCode = resp.statusCode;
if (statusCode !== 200) {
callback('Error: HTTP ' + statusCode);
return;
}
var chunks = [];
resp.on('data', function(chunk) {
chunks.push(chunk);
});
resp.on('end', function() {
if (chunks.length > 0) {
var decoded = iconv.decode(Buffer.concat(chunks), 'cp437');
callback(iconv.encode(decoded, 'utf8').toString());
} else {
callback('Error: No data received');
}
});
}).on('error', function(error) {
callback(error);
});
} else {
callback('Error: Invalid URL');
}
}
module.exports = shownfo;