Skip to content

Instantly share code, notes, and snippets.

@teemow
Created September 6, 2010 13:46
Show Gist options
  • Save teemow/567057 to your computer and use it in GitHub Desktop.
Save teemow/567057 to your computer and use it in GitHub Desktop.
#!/usr/bin/env node
var http = require('http')
, fs = require('fs')
, sys = require('sys');
var client = http.createClient(5984, '127.0.0.1');
var doc = client.request('PUT', '/test_db/doc_att_deflate', {
'Content-type': 'application/json',
'Referer': 'http://127.0.0.1:5984/test_db'
});
doc.on('response', function(response) {
var file = fs.readFileSync("readme.gz");
// file = "";
sys.puts(sys.inspect(file.length));
var req = client.request('PUT', '/test_db/doc_att_deflate/readme.txt', {
'Content-type': 'text/plain',
'Content-length': file.length,
'Content-encoding': 'deflate',
'Referer': 'http://127.0.0.1:5984/test_db'
});
req.on('response', function(res) {
sys.puts(sys.inspect(res.statusCode));
var body = '';
res.on('data', function(chunk) {
sys.puts(sys.inspect('chunk'));
body += chunk
})
res.on('end', function() {
sys.puts(body);
});
});
req.end(file);
});
doc.end('{"foo":"bar"}')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment