Comments (26)
gist me some code here please
from nano.
If this doesnt break api and other clients, go ahead and commit
from nano.
The current behaviour is just wrong.
In https://github.com/dscape/nano/blob/master/nano.js#L512 you pass the encoding as "binary". This is just wrong because, according to the Node docs:
"binary": A way of encoding raw binary data into strings by using only the first 8 bits of each character. This encoding method is deprecated and should be avoided in favor of Buffer objects where possible. This encoding will be removed in future versions of Node.
You should force {encoding: null}
in request arguments, so a buffer is returned.
from nano.
Will you accept a pull request with this change? :)
from nano.
If it doesn't break tests yes. Also it shouldn't break current behavior.
from nano.
Also does it work in expensecat with the changes you proposed? Does the pipe example in samples work?
from nano.
It works for expensecat by doing the change.
Current behavior seams plain wrong, this is not usable IMO.
I got a file as a string, saved it and was totally borked, which is understandable given the given encoding.
from nano.
@pgte have you tried it in 0.4.12
. I think it will work there, but it's probably broken in 0.6
.
Fix needs to pass in both test sets.
Also make sure this is being tested. It should, but just in case! I'm wondering why current tests pass???
https://github.com/dscape/nano/blob/master/tests/att/pipe.js#L8
If what you are saying is true, it shoudn't?
from nano.
Maybe try run tests without nock
. How can I make it not use nock?
NOCK_OUT=true node mytests.js
?
from nano.
@dscape I'm using 0.4.11.
from nano.
Shouldn't that test case be broken then?
We should meet and discuss this in detail.
Btw you are a repo collab, you can pretty much commit upstream as you like
(even though I'm sure companies using nano appreciate being warned about
these issues and following the discussion here)
from nano.
@pgte how can i do this?
NOCK_OUT=true node mytests.js
I need to test this with iris couch
from nano.
Pedro ping me on this monday or so so we can discuss / patch
from nano.
Sorry, too busy, I'll ping you monday.
No dia 15/01/2012, às 01:30, Nuno Job
[email protected]
escreveu:
Pedro ping me on this monday or so so we can discuss / patch
Reply to this email directly or view it on GitHub:
#49 (comment)
from nano.
For some reason nano attachments are working when they're piped, but not when they're being transfered in bulk.
For testing this I created a local database named "tests" and created this object and attached "js.png"
{
"_id": "60a83e3b23fe83a873105c0ef1000ad7",
"_rev": "2-2c4296b27533399ec1690eaf154f4950",
"a": 1,
"_attachments": {
"js.png": {
"content_type": "image/png",
"revpos": 2,
"length": 10268,
"stub": true
}
}
}
Then I ran this code:
var fs = require('fs')
, db = require('nano')('http://127.0.0.1:5984').use('tests');
function error(err) {
throw err;
}
// ------- piping
(function() {
var rs = db.attachment.get('60a83e3b23fe83a873105c0ef1000ad7', 'js.png');
rs.on('error', error);
var ws = fs.createWriteStream(__dirname + '/js.piped.png');
ws.on('error', error);
rs.pipe(ws);
}());
// ------- getting
(function() {
db.attachment.get('60a83e3b23fe83a873105c0ef1000ad7', 'js.png', function(err, image) {
if (err) { throw err; }
fs.writeFile(__dirname + '/js.got.png', image, function(err) {
if (err) { throw err; }
});
});
}());
It outputs 2 files:
- js.piped.png
- js.got.png
If you run this you will see the output files:
pedroteixeira:temp pedroteixeira$ ls -la *.png
-rw-r--r-- 1 pedroteixeira staff 14678 Jan 16 09:50 js.got.png
-rw-r--r-- 1 pedroteixeira staff 10268 Jan 16 09:50 js.piped.png
You can see that the sizes are different. Also, the js.got.png is corrupted:
pedroteixeira:temp pedroteixeira$ file js.piped.png
js.piped.png: PNG image data, 1052 x 1052, 8-bit colormap, non-interlaced
pedroteixeira:temp pedroteixeira$ file js.got.png
js.got.png: data
from nano.
Go ahead and submit the pull request. Also add that one that fails to the test case.
I can do this myself but didn't cause I suppose you already have it :)
from nano.
Also how can we nock
this ?
from nano.
Was this fixed?
from nano.
I've tried to fix this in my attachment-buffer
branch. I was just messing around to figure out if this was doable, so I didn't take a look at the tests. But the fix I applied works with @pgte's sample.
The relevant commit is 9ba2f2
from nano.
@pgte can you please review? I never had this issue
from nano.
@dscape Yes, that's exactly what my fix was that I had in a branch somewhere.
Looks good to me.
from nano.
So I guess the problem boils down to backwards compatibility testing. I'll get to it when I have some time (which, admittedly, may turn out to be some weeks), but shouldn't we consider working with buffers even if it breaks backwards compatibility? Strings and encoding for binary files seem to be getting deprecated in node, and buffers can be encoded/decoded to/from strings if needed anyway.
from nano.
Just a little addendum as to the evidence of Buffers being preferred instead of binary encoded strings (which is the solution we're using in nano right now): take a look at the description for the binary encoding at http://nodejs.org/api/buffer.html#buffer_buffer
from nano.
Test Run is available here:
If you guys can add the tests that were failing I would really appreciate it.
Nuno
from nano.
I've taken the liberty to add a test for attachments as buffers to the main master. Feel free to revert if you see the need.
from nano.
Great stuff, thanks Thiago :)
from nano.
Related Issues (20)
- Does nano support purge? HOT 2
- db.attachment.get file- 'could not be opened because it is empty'
- Can not get correct userctx HOT 2
- Couch DB 2 compatibilty HOT 3
- bulk() with _deleted:true causes error HOT 3
- db.multipart.get does not work with Cloudant Local 1.0.0.5 HOT 1
- Enable permanent replication by writing to "_replicator" database instead of "_replicate" database. HOT 3
- Support temp view
- Doubt on db access of live app HOT 2
- What is the keys in view function based on? Is it the key you emit in the views/map function? HOT 1
- How do you update _rev to update a document?
- uploaded files displaying base64 data in the browser (attachments not viewable)
- Problem with OR -clauses? HOT 1
- Error: badarg every few hours
- Error: {error,emfile} HOT 1
- Example Lazy Creation of View
- Query string encoded when using array of keys
- Database permissions
- db.fetch array of id error
- Attempting to return simple list of documents, small issue
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nano.