torrent: calculate piece length depending on file size

front
cinap_lenrek 2011-10-25 14:55:24 +02:00
parent f8d5cc7230
commit 83865180a2
1 changed files with 6 additions and 2 deletions

View File

@ -764,8 +764,12 @@ mktorrent(int fd, char *url)
werrstr("empty file"); werrstr("empty file");
return -1; return -1;
} }
blocksize = 1024*1024; npieces = 1;
npieces = (d->length + blocksize-1) / blocksize; for(blocksize = 256*1024;;blocksize<<=1){
npieces = (d->length + blocksize-1) / blocksize;
if(npieces <= 8*1024 || blocksize >= 2*1024*1024)
break;
}
print("d"); print("d");
print("8:announce%ld:%s", strlen(url), url); print("8:announce%ld:%s", strlen(url), url);
print("4:info"); print("4:info");