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

How to save file with node fs #1631

Closed
MarchWorks opened this issue May 19, 2019 · 6 comments
Closed

How to save file with node fs #1631

MarchWorks opened this issue May 19, 2019 · 6 comments

Comments

@MarchWorks
Copy link

@MarchWorks MarchWorks commented May 19, 2019

What version of WebTorrent?
latest

How to save file with fs

var magnetURI = '........'
const downloadPath = app.getPath('downloads')
client.add(magnetURI, function (torrent) {
    // Got torrent metadata!
    console.log('Client is downloading:', torrent.infoHash)
    torrent.files.forEach(function (file) {
        fs.outputFile(downloadPath + file.path , file, 'utf-8') // what should I do here 
    })
}) 
@MarchWorks

This comment has been minimized.

Copy link
Author

@MarchWorks MarchWorks commented May 19, 2019

I found out

@MarchWorks MarchWorks closed this May 19, 2019
@MarchWorks

This comment has been minimized.

Copy link
Author

@MarchWorks MarchWorks commented Dec 26, 2019

@Senicolonna are you sure that { path: 'your_pathname'} download only the first file? Well here is what you want

torrent.files.forEach(function (file) {
	  	file.getBuffer(async function (err, buffer) {
		  if (err) throw err
		  await fs.outputFile(downloadPath + (downloadPath.endsWith('/') ? '' : '/') + file.path , buffer, 'binary')
		})
	  })
@MarchWorks

This comment has been minimized.

Copy link
Author

@MarchWorks MarchWorks commented Dec 26, 2019

open a new issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.