Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 2405b57
Showing
4 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
replicate-http | ||
==== | ||
|
||
Copy remote files with webdav protocol by urls. | ||
|
||
``` | ||
npm install replicate-http | ||
``` | ||
|
||
### Usage | ||
|
||
Note that destination must support webdav PUT method. | ||
|
||
```javascript | ||
var replicate = require("replicate-http"); | ||
|
||
replicate("http://pewpewpew.com/passwords.txt", "http://backup.pewpewpew.com/passwords.txt", function() { | ||
if (error) { | ||
throw error; | ||
} | ||
|
||
console.log("File successfully copied!"); | ||
}); | ||
|
||
``` | ||
|
||
### Authors | ||
|
||
* [Ian Babrou](https://github.com/bobrik) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
(function(module) { | ||
var http = require("http"), | ||
url = require("url"); | ||
|
||
module.exports = function(from, to, callback) { | ||
var toUrl = url.parse(to), | ||
put; | ||
|
||
http.get(from, function(res) { | ||
res.on("error", callback); | ||
|
||
if (res.statusCode != 200) { | ||
res.on("end", function() { | ||
callback(new Error("Got http code " + res.statusCode + " for " + from)); | ||
}); | ||
|
||
// suck stream in | ||
res.resume(); | ||
} else { | ||
put = http.request({ | ||
host : toUrl.hostname, | ||
port : toUrl.port, | ||
method : "PUT", | ||
path : toUrl.path, | ||
headers : { | ||
"Content-Length": res.headers['content-length'] | ||
} | ||
}); | ||
|
||
put.on("response", function(res) { | ||
if (res.statusCode != 201 && res.statusCode != 204) { | ||
res.on("end", function() { | ||
callback(new Error("HTTP put failed with code " + res.statusCode + " for " + to)); | ||
}); | ||
} else { | ||
res.on("end", callback); | ||
} | ||
|
||
// suck stream in | ||
res.resume(); | ||
}); | ||
|
||
put.on("end", callback); | ||
put.on("error", callback); | ||
|
||
res.pipe(put); | ||
} | ||
}).on("error", callback); | ||
}; | ||
})(module); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"name": "replicate-http", | ||
"version": "0.1.0", | ||
"description": "Replicate remote files by webdav protocol.", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git@github.com:Topface/node-replicate-http.git" | ||
}, | ||
"keywords": [ | ||
"webdav", | ||
"dav", | ||
"http", | ||
"replicate", | ||
"copy" | ||
], | ||
"author": "Ian Babrou <ibobrik@gmail.com> (http://bobrik.name/)", | ||
"license": "BSD" | ||
} |