-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
37 lines (31 loc) · 1001 Bytes
/
index.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
31
32
33
34
35
36
37
var tftp = require('tftp');
var extend = require('extend');
module.exports = function setup (protocols) {
protocols.tftp = get;
};
/**
* Returns a Readable stream from a "tftp:" URI.
* There are no caching semantics within TFTP. There is no safe way to
* cache information using the TFTP protocol.
*
* TFTP URI: http://www.ietf.org/rfc/rfc3617.txt
*
* @api protected
*/
function get (parsed, opts, fn) {
var client = tftp.createClient(extend({
host: parsed.hostname,
port: +parsed.port
}, opts));
var pathname = parsed.pathname;
if (pathname[0] === '/') pathname = pathname.substring(1);
var colon = pathname.indexOf(';');
if (-1 !== colon) {
// the RFC specifies that a "mode=" value (octet or netascii) can
// be specified after the colon, but we just throw it away since
// the `tftp` module doesn't seem to care about this option
pathname = pathname.substring(0, colon);
}
var rs = client.createGetStream(pathname, opts);
fn(null, rs);
}