Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trying to process more than one image: crypto HashUpdate fail #10

Closed
edjroot opened this issue Oct 22, 2015 · 5 comments
Closed

Trying to process more than one image: crypto HashUpdate fail #10

edjroot opened this issue Oct 22, 2015 · 5 comments

Comments

@edjroot
Copy link

edjroot commented Oct 22, 2015

I'm trying to implement a page with express and multer where uploaded images should be immediately processed by mapslice. It works fine with the first image, but fails for the second one, whether I try to upload both at the same time or sequentially:

crypto.js:70
  this._handle.update(data, encoding);
               ^
TypeError: HashUpdate fail
[....]

In nodejs/node-v0.x-archive#1415 it is stated that "crypto instances are not reusable", so I guess the script is trying to reuse the same object for the second image. Is this a bug in mapslice or am I doing something wrong?

The following code reproduces the problem, although it's not exactly what I'm using:

var mapslice = require('mapslice');

var mapSlicer = mapslice({
  file: 'myimg.png'
})
  .on("start", function(files, options) {
    console.info("Processing first image....");
})
  .on("end", function() {
    console.info("Finished processing first image.\n\nProcessing second image....");

    var mapSlicer2 = mapslice({
      file: 'myimg.png'
    }).start();
}).start();
@edjroot
Copy link
Author

edjroot commented Oct 22, 2015

Alright, I just looked at MapSlicer.js. I removed line 15 (sha1 = crypto.createHash('sha1');) and changed line 122 to (patternMd5 = crypto.createHash('sha1').update(this.options.output).digest("hex");) and now it seems to be working. Is this a right change for a pull?

@martinheidegger
Copy link
Owner

Thank you for fixing it. It is a slightly weird way to create PR though the code landed in master and is published as 1.0.3 @ npm. Again thanks and best regards!

@edjroot
Copy link
Author

edjroot commented Oct 23, 2015

No problem! It makes me happy to know I could finally help with something, even it being so simple, for the first time in my life.

Sorry for the noobish questions, but I don't understand what you mean by "It is a slightly weird way to create PR". What is PR? Are you referring to the way it was before of after I changed the code?

Best regards!

@martinheidegger
Copy link
Owner

A "PR" or "Pull Request" is the-github-way™ to collaborate. Github has a guide that explains it here

@edjroot
Copy link
Author

edjroot commented Oct 29, 2015

Oh, of course. I thought it had something to do with mapslice itself. I should have thought a little more before asking. Thanks!

Now, I promise this is the last question, but I really want to learn the right way to do this stuff. What was weird about the way I created the PR? I've already read the guide before, but I'm not sure. Is it because I opened an issue and linked it to the PR? If so, I apologize. I only thought about trying to fix the bug myself after opening the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants