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

Fatal error: Second argument needs to be a buffer #250

Open
kundaiAtPropertyMe opened this issue Jun 8, 2017 · 4 comments
Open

Fatal error: Second argument needs to be a buffer #250

kundaiAtPropertyMe opened this issue Jun 8, 2017 · 4 comments

Comments

@kundaiAtPropertyMe
Copy link

Since I upgrade node.js version to the latest (8.0), when I use rest.post(url, options) to post a sourcemap file (json), it returns error Fatal error: Second argument needs to be a buffer

@kundaiAtPropertyMe
Copy link
Author

since fs.read is changed by node and older function is removed.

The way to resolve this bug is modify the multipartform.js file

change the write function

write: function(stream, callback) {

var self = this;

  //first write the Content-Disposition
  stream.write(this.header());

//Now write out the body of the Part
if (this.value instanceof File) {
  fs.open(this.value.path, 'r+', function (err, fd) {
      var stats = fs.fstatSync(fd);
      var bufferSize = stats.size
	  if (err) throw err; 
	  var chunkSize = 512;
	  var position = 0;
      var buf = new Buffer(bufferSize);
    (function reader () {

        if ((position + chunkSize) > bufferSize) {
            chunkSize = (bufferSize - position);
        }

      fs.read(fd, buf, position, chunkSize, position,  function (er, chunk, buf) {
        if (er) callback(err);
        stream.write(buf.slice(position, chunkSize + position));
        position += chunkSize;
        if (position < bufferSize) reader();
        else {
		      stream.write("\r\n")
  			  callback();
  			  fs.close(fd);
  			}
      }); 
    })(); // reader() 
  });
 } else if (this.value instanceof Data) {
  stream.write(this.value.data);
  stream.write("\r\n");
  callback();
 } else {
  stream.write(this.value + "\r\n");
  callback();
}

}

@kundaiAtPropertyMe
Copy link
Author

create fork and send pull request about this change
#251

@tkristensen
Copy link

+1 on merging this, I'd like to use restler in Node LTS builds but can't without this error resolved.

@reco
Copy link

reco commented Dec 10, 2017

+1 yes please merge. is there a reason not to?

kolbasa pushed a commit to CoredinateDE/restler that referenced this issue Mar 4, 2018
kolbasa pushed a commit to CoredinateDE/restler that referenced this issue Mar 4, 2018
kolbasa pushed a commit to CoredinateDE/restler that referenced this issue Mar 4, 2018
kolbasa pushed a commit to CoredinateDE/restler that referenced this issue Mar 4, 2018
educhastenier pushed a commit to bonitasoft/bonita-distrib that referenced this issue Jul 3, 2018
Remove e2e test that is useless since it is ever green whatever code is tested.
Also remove all protractor conf since it was the only e2e test for this page.

* Remove useless test
* Remove protractor and gulp configuration
* Remove reslter dependency which is not compatible with recent node versions ([Github issue](danwrong/restler#250))
* Prepare ymci integration
educhastenier pushed a commit to bonitasoft/bonita-distrib that referenced this issue Jul 3, 2018
Remove e2e test that is useless since it is ever green whatever code is tested.
Also remove all protractor conf since it was the only e2e test for this page.

* Remove useless test
* Remove protractor and gulp configuration
* Remove reslter dependency which is not compatible with recent node versions ([Github issue](danwrong/restler#250))
* Prepare ymci integration
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

3 participants