Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added index.js for better npm support. Started a very simple binary. …

…Added more TODOs.
  • Loading branch information...
commit e6ac44b148455a5d3122ae15c7aa290a6ced478d 1 parent 6724159
@slaskis slaskis authored
View
9 README.md
@@ -94,7 +94,16 @@ Uses the [addressable module](https://github.com/publicclass/addressable) for pa
* Get the tests to pass, having some issues with faking a Writeable Stream.
+* A binary, just for fun really. Usage: `open-uri http://google.com`.
+ - Output to process.stdout by default.
+ - Allow a REST interface? So if something is written to stdin it's sent as body to the url using POST by default, but definable with -X (curl style!)
+ - Pass command line arguments as options to the scheme functions. Ex. `open-uri -gzip http://google.com` sets opts.gzip to true.
+
* More schemes support? Suggestions?
+ - SQL query. Is there a standard URI for this? Something like: `mysql://root@localhost/mydb?query=SELECT * FROM x;` or `sqlite3://file.sqlite?query=SELECT * FROM x;` possibly with support for input escaping. open("sqlite3://file.sqlite?query=SELECT * FROM x WHERE id=? AND name=?;",[12,"bob"]) using the drivers own escaping. With a callback like `function(err,rows,meta){}`.
+ - NNTP (using [node-nntp module](https://github.com/mscdex/node-nntp))
+
+* A little refactoring so we'd do `require("./open-uri/"+uri.scheme)` in the main function and keep the different schemes in separate files.
## Thanks to
View
6 bin/open-uri
@@ -0,0 +1,6 @@
+#!/usr/bin/env node
+
+var open = require("../lib/open-uri")
+ , uri = process.argv[0] == "node" ? process.argv[2] : process.argv[3];
+
+open(uri,process.stdout)
View
1  index.js
@@ -0,0 +1 @@
+module.exports = require("lib/open-uri")
View
6 lib/open-uri.js
@@ -56,7 +56,7 @@ open.http = function(uri,opts,output){
opts.headers.host = addressable.parse(res.headers.location).host;
return open(res.headers.location,opts,output);
}
- // TODO How should other statusCodes be handled? (like 403, 404, 500), should they be 0returned as an Error?
+ // TODO How should other statusCodes be handled? (like 403, 404, 500), should they be returned as an Error?
var stream = res;
if( gzip && ~(res.headers['content-encoding']||"").indexOf("gzip") )
res.pipe(stream = new compress.GunzipStream());
@@ -122,7 +122,6 @@ open.ftp = function(uri,opts,output){
uri.password = "anonymous@";
}
- client.on("timeout",function(){ error(output,new Error("[OpenURI] Connection timed out.")) })
client.on("connect",function request(err){
if( err ) return error(output,err);
@@ -165,8 +164,9 @@ function buffer(type,path,stream,output){
type = mime.lookup(type||path||'')
var buf = [], len = 0;
stream.setEncoding(mime.charsets.lookup(type))
- stream.on("data",function(chunk){ buf.push(chunk); len += chunk.len; })
stream.on("error",function(err){ error(output, err) }) // TODO Close the stream on error?
+ stream.on("timeout",function(){ error(output,new Error("[OpenURI] Connection timed out.")) }) // TODO Close the stream on timeout?
+ stream.on("data",function(chunk){ buf.push(chunk); len += chunk.len; })
stream.on("end",function(){ output(null,parse(type,buf,len),stream) })
}
View
15 test/test-open-uri.js
@@ -25,7 +25,7 @@ exports["Get a website"] = function(beforeExit){
exports["Get a relative file"] = function(beforeExit){
var loaded = false;
- open("../README.md",function(err,log){
+ open("README.md",function(err,log){
loaded = true;
assert.ifError(err)
assert.type(log.toString(),"string")
@@ -65,6 +65,16 @@ exports["Get a text file from ftp"] = function(beforeExit){
beforeExit(function(){assert.ok(loaded)})
}
+exports["Attempt to get a non-existing text file from ftp"] = function(beforeExit){
+ var loaded = false;
+ open("ftp://ftp.sunet.se/im-not-here.txt",function(err,rfc){
+ loaded = true
+ assert.ok(err)
+ assert.type(rfc,"undefined")
+ })
+ beforeExit(function(){assert.ok(loaded)})
+}
+
exports["Stream a text file from ftp to a file"] = function(beforeExit){
var path = "/tmp/rfc-"+Date.now()+".html";
var file = require("fs").createWriteStream(path)
@@ -97,9 +107,8 @@ exports["Throw when error without callback."] = function(){
})
}
-
exports["Does not throw when error with a callback."] = function(){
assert.doesNotThrow(function(){
open("/i-dont-exist!",function(err){ assert.ok(err) })
})
-}
+}
Please sign in to comment.
Something went wrong with that request. Please try again.