bendrucker/stream-to-promise

Putting a buffer through stream-to-promise - question

rug1 opened this issue · 2 comments

rug1 commented

I'm using the stream-to-promise module to create the multipart/form-data payload in my jasmine test. My payload includes an image file as a buffer but when the payload is put through stream-to-promise it changes or corrupts my original image buffer in the payload somehow to return something different and so my tests are failing. Is there a way to prevent this?

  it('test /identity-verification/your-first-form-of-id POST with validation passing', function(done){
    var form = new FormData();
    var image = fs.createReadStream("image.png");
    streamToBuffer(image, function (err, buffer) {
      form.append('firstID', 'passport');
      form.append('firstIDImage', buffer);
      var headers = form.getHeaders();
      streamToPromise(form).then(function(payload) {
        var options = {
          method: 'POST',
          url: '/identity-verification/your-first-form-of-id',
          payload: payload,
          headers: headers
        };
        server.inject(options, function(response) {
          expect(response.statusCode).toBe(302);
          expect(response.headers.location).toMatch('/identity-verification/your-first-form-of-id/upload-successful');
          done();
        });
      });
    });
  });

The buffer in the payload after being put through stream-to-promise looks like this:
a

Not much going on here so I'm not sure how it could be changing your data. What you have doesn't necessarily look wrong. That looks like what would happen when you try to stringify binary data from a Buffer.

rug1 commented

I removed streamToBuffer and it all worked fine. Thanks.