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

Upload of a 0 byte file fails #23

Closed
robogeek opened this issue Jan 27, 2013 · 1 comment
Closed

Upload of a 0 byte file fails #23

robogeek opened this issue Jan 27, 2013 · 1 comment

Comments

@robogeek
Copy link

In my file synchronize tool (https://github.com/robogeek/node-ssh2sync) I had to work around a zero length file issue.

I'm doing

fs.readFile(localfile, function(err, data) {

followed by

sftp.write(handle, data, 0, data.length, 0, function(err) {

But was given an error about the offset being out of bounds. Well, yes, it is a zero length file, so therefore data.length is zero. Seems to me it shouldn't throw an error but should just go about writing a 0 length file on the server. FWIW the file does get created.

In my script I'm testing for 0 length buffer and handling it this way

if (data.length === 0) {
                                            closehandle(handle, remotefile, statz, cb);
                                        } else {
                                            sftp.write(handle, data, 0, data.length, 0, function(err) {
                                                if (err) {
                                                    cb(err);
                                                } else {
                                                    closehandle(handle, remotefile, statz, cb);
                                                }
                                            });
                                        }
@mscdex
Copy link
Owner

mscdex commented Jan 27, 2013

For almost all of the sftp functions, I used node's fs binding implementation as a guide. So generally it should work the same in both places.

@mscdex mscdex closed this as completed Feb 12, 2013
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