GithubHelp home page GithubHelp logo

Comments (26)

dscape avatar dscape commented on July 24, 2024

gist me some code here please

from nano.

dscape avatar dscape commented on July 24, 2024

If this doesnt break api and other clients, go ahead and commit

from nano.

pgte avatar pgte commented on July 24, 2024

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.

pgte avatar pgte commented on July 24, 2024

Will you accept a pull request with this change? :)

from nano.

dscape avatar dscape commented on July 24, 2024

If it doesn't break tests yes. Also it shouldn't break current behavior.

@perezd @mikeal opinions?

from nano.

dscape avatar dscape commented on July 24, 2024

Also does it work in expensecat with the changes you proposed? Does the pipe example in samples work?

from nano.

pgte avatar pgte commented on July 24, 2024

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.

dscape avatar dscape commented on July 24, 2024

@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.

dscape avatar dscape commented on July 24, 2024

Maybe try run tests without nock. How can I make it not use nock?

NOCK_OUT=true node mytests.js

?

from nano.

pgte avatar pgte commented on July 24, 2024

@dscape I'm using 0.4.11.

from nano.

dscape avatar dscape commented on July 24, 2024

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.

dscape avatar dscape commented on July 24, 2024

@pgte how can i do this?

NOCK_OUT=true node mytests.js

I need to test this with iris couch

from nano.

dscape avatar dscape commented on July 24, 2024

Pedro ping me on this monday or so so we can discuss / patch

from nano.

pgte avatar pgte commented on July 24, 2024

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.

pgte avatar pgte commented on July 24, 2024

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.

dscape avatar dscape commented on July 24, 2024

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.

dscape avatar dscape commented on July 24, 2024

Also how can we nock this ?

from nano.

dscape avatar dscape commented on July 24, 2024

Was this fixed?

from nano.

thiagoarrais avatar thiagoarrais commented on July 24, 2024

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.

dscape avatar dscape commented on July 24, 2024

@pgte can you please review? I never had this issue

from nano.

pgte avatar pgte commented on July 24, 2024

@dscape Yes, that's exactly what my fix was that I had in a branch somewhere.
Looks good to me.

from nano.

thiagoarrais avatar thiagoarrais commented on July 24, 2024

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.

thiagoarrais avatar thiagoarrais commented on July 24, 2024

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.

dscape avatar dscape commented on July 24, 2024

Test Run is available here:

If you guys can add the tests that were failing I would really appreciate it.

Nuno

from nano.

thiagoarrais avatar thiagoarrais commented on July 24, 2024

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.

dscape avatar dscape commented on July 24, 2024

Great stuff, thanks Thiago :)

from nano.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.