remote-fs.js
926 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
36
37
38
39
// Copyright IBM Corp. 2013,2016. All Rights Reserved.
// Node module: strong-remoting
// This file is licensed under the Artistic License 2.0.
// License text available at https://opensource.org/licenses/Artistic-2.0
// create a set of shared classes
var remotes = require('../').create();
// share some fs module code
var fs = remotes.exports.fs = require('fs');
// specifically the createReadStream function
fs.createReadStream.shared = true;
// describe the arguments
fs.createReadStream.accepts = {arg: 'path', type: 'string'};
// describe the stream destination
fs.createReadStream.http = {
// pipe to the response
// for the http transport
pipe: {
dest: 'res'
}
};
// over rest / http
require('http')
.createServer(remotes.handler('rest'))
.listen(3000);
/*
Test the above with curl or a rest client:
$ node remote-fs.js
$ curl http://localhost:3000/fs/createReadStream?path=simple.js
*/