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

Why when i try to get Buffer of downloaded file (client.torrents[0].files[0].getBuffer();i get error (TypeError: can't convert undefined to object)? #1247

Closed
VladChekunov opened this issue Dec 18, 2017 · 4 comments
Labels

Comments

@VladChekunov
Copy link

@VladChekunov VladChekunov commented Dec 18, 2017

What version of WebTorrent?
Last
What browser and version? (if using WebTorrent in the browser)
Last version of Firefox, also Firefox ESR 48.
What did you expect to happen?
Get file data by buffer of bytes.
What actually happened?
i get error (TypeError: can't convert undefined to object).

@sevchan

This comment has been minimized.

Copy link

@sevchan sevchan commented Dec 19, 2017

I use this code for testing and too get this error:

<html>
<head>
<meta charset="utf-8">
<script src="https://cdn.jsdelivr.net/webtorrent/latest/webtorrent.min.js"></script>
<script>
var client = new WebTorrent();

function sendHello(){
	parts = [new Blob(["Hello Worldddddd"], {type: 'text/plain'})];
	var file = new File(parts, 'hello2017worldtorrent.txt', {
	    lastModified: new Date(0),
	    type: "text/plain"
	});
	client.seed(file, function (torrent) {
		alert(torrent.magnetURI);//I save this value from alert and paste it to torrentId in getHello() function.
	});
}

function getHello(){
	var torrentId = 'magnet:?xt=urn:btih:3a0dbec572713c018afad430f7ec199966539384&dn=hello2017worldtorrent.txt&tr=udp%3A%2F%2Fexplodie.org%3A6969&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Ftracker.empire-js.us%3A1337&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337&tr=wss%3A%2F%2Ftracker.btorrent.xyz&tr=wss%3A%2F%2Ftracker.fastcast.nz&tr=wss%3A%2F%2Ftracker.openwebtorrent.com';
	client.add(torrentId, function (torrent) {
	  var file = torrent.files.find(function (file) {
	    console.log(file.getBuffer());//Here i get error TypeError: can't convert undefined to object.
	  })
	})
}

</script>
</head>
<body>
<a  onclick="sendHello();" href="javascript://">Send</a>
<a  onclick="getHello();" href="javascript://">Get</a>
</div>
</body>
</html>
@DiegoRBaquero

This comment has been minimized.

Copy link
Member

@DiegoRBaquero DiegoRBaquero commented Dec 19, 2017

Could you please post a full stack trace?

@sevchan

This comment has been minimized.

Copy link

@sevchan sevchan commented Dec 22, 2017

Could you please post a full stack trace?

@DiegoRBaquero, how to do it?

@stale stale bot added the stale label May 3, 2018
@feross

This comment has been minimized.

Copy link
Member

@feross feross commented May 4, 2018

@sevchan I found the issue in your code. You're calling file.getBuffer() without a callback. The docs say the prototype is file.getBuffer(function callback (err, buffer) {}).

@feross feross closed this May 4, 2018
@webtorrent webtorrent deleted a comment from stale bot May 4, 2018
@lock lock bot locked as resolved and limited conversation to collaborators Jan 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.