This repository has been archived by the owner on Nov 5, 2018. It is now read-only.
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
Showing
6 changed files
with
83 additions
and
36 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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,2 +1,3 @@ | |||
.DS_Store | .DS_Store | ||
node_modules/ | node_modules/ | ||
*tmp.* |
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
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
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
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
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,44 @@ | |||
var vows = require('vows') | |||
, fs = require('fs') | |||
, assert = require('assert') | |||
, cfg = require('../../cfg/tests.js') | |||
, nano = require('../../nano')(cfg) | |||
, pixel = "Qk06AAAAAAAAADYAAAAoAAAAAQAAAP////8BABgAAAAAAAAAAAATCwAAEwsAAAAAAAAAAAAAWm2CAA=="; | |||
|
|||
function db_name(i) { return "att_pi" + i; } | |||
function db(i) { return nano.use(db_name(i)); } | |||
function file_name(i) { return __dirname + "/." + i + "-tmp.bmp"; } | |||
function f_s(i) { return fs.createWriteStream(file_name(i)); } | |||
|
|||
/***************************************************************************** | |||
* att_pipe * | |||
*****************************************************************************/ | |||
function att_pipe(callback) { | |||
var buffer = new Buffer(pixel, 'base64') | |||
, file_stream = f_s("a"); | |||
file_stream.on("close", function() { callback(); }); | |||
nano.db.create(db_name("a"), function () { | |||
db("a").attachment.insert("new", "att", "Hello", "text/plain", | |||
function(e,_,b) { | |||
if(e) { callback(e); } | |||
db("a").attachment.insert("new", "att", buffer, "image/bmp", {rev: b.rev}, | |||
function (e2,_,b2) { | |||
if(e2) { callback(e2); } | |||
db("a").attachment.get("new", "att", {rev: b2.rev}).pipe(file_stream); | |||
}); | |||
}); | |||
}); | |||
} | |||
|
|||
function att_pipe_ok() { | |||
nano.db.destroy(db_name("a")); | |||
console.log(file_name("a")) | |||
assert.equal(fs.readFileSync(file_name("a")).toString("base64"), pixel); | |||
//fs.deleteFileSync(file_name("a")); | |||
} | |||
|
|||
vows.describe('attachment.pipe').addBatch({ | |||
"att_pipe": { | |||
topic: function () { att_pipe(this.callback); } | |||
, "=": att_pipe_ok } | |||
}).exportTo(module); |