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

writeStream not work but putFileContents('xxx', stream) work well #375

Open
huangganggui opened this issue May 16, 2024 · 1 comment
Open

Comments

@huangganggui
Copy link

huangganggui commented May 16, 2024

Hi, I want to use createWriteStream to upload a local file.

      const writeStream = webdavClient.createWriteStream(remoteFileUrl);
      const readStream = fs.createReadStream(localFile);
      const uploadPromise = new Promise((resolve, reject) => {
        readStream.on('error', (error)=>{
          console.log(error)
          reject()
        });

        readStream.on('data', function(chunk) {
          console.log('readtrunk',chunk);
        });

        writeStream.on('data', function(chunk) {
          console.log('writetrunk',chunk);
        });

        writeStream.on('error', (error)=>{
          console.log(error)
          reject()
        });
        writeStream.on('finish', resolve);
        writeStream.on('pipe', (src) => {
          console.log('Something is piping into the writer.');
        });
      });
      readStream.pipe(writeStream);


      await uploadPromise;

      const readStreamDebug = fs.createReadStream(localFile);
      await webdavClient.putFileContents(remoteFileUrl+'debug.txt', readStreamDebug);
      console.log('uploaded ' + remoteFileUrl);

the remoteFileUrl created, but file content is empty.
but remoteFileUrl+'debug.txt' works well,

I dont know why createWriteStream not work( writeStream on data can print content data, but file is empty) . I have to uses putFileContents to walk around.

@perry-mitchell
Copy link
Owner

Write streams are tricky, but the tests are currently working for writing: https://github.com/perry-mitchell/webdav-client/blob/master/test/node/operations/createWriteStream.spec.ts

Are you able to work back from the tests if you haven't already moved on?

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