takeout
A Node module to get the file contents, seamlessly available for both local file system and HTTP(S)
var takeout = ; // Reading a local file; // GET request if the location is URL;
Installation
npm install takeout
API
var takeout = ;
takeout(location,[ options,] callback)
location: String
(local file path or URL)
options: Object
callback: Function
If the location is a local file path, it reads the file with fs.readFile. If the locatiandon is a URL, it makes a GET request to the URL and grabs its response, using got.
// `http` and `https` scheme is optional.;
options
In addition to the following, all options for fs.readFile and got are available.
options.encoding
Type: String
or null
Default: null
(In other words, the content is returned as a Buffer
by default.)
Directly passed to fs.readFile options or setEncoding
of the response data.
options.directoryIndex
Type: Boolean
or String
of filename
Default: index.html
When the path indicates a local directory, it reads index.html
or a file with the specified filename immediately under the directory.
false
disables this feature.
// |// +- dist// +- index.html ('foo')// +- home.html ('bar') ; ; ;
callback(error, body, response)
error: Error
if it fails to get the contents, otherwise null
body: Buffer
or String
(according to options.encoding
)
response: Object
(response object) if the content is got via HTTP(S), otherwise undefined
CLI
You can use this module as a CLI tool by installing it globally.
npm install -g takeout
Usage
Usage1: takeout <file path | URL> --out <dest>Usage2: takeout <file path | URL> > <dest> Options:--out, -o <file path> Write the result to a file --encoding, -e <encoding> Set encoding
You can do almost the same thing with cat
and curl
. But this tool works on various environments, as long as they supports Node.
License
Copyright (c) 2014 Shinnosuke Watanabe
Licensed under the MIT License.