Advertisement
dimonbb

Untitled

Sep 2nd, 2018
376
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.65 KB | None | 0 0
  1. import tarfile
  2. import requests
  3.  
  4. class PDownload(object):
  5.     def __init__(self, url):
  6.         self.url = url
  7.         self.current = 0
  8.         self.session = requests.Session()
  9.  
  10.     def tell(self):
  11.         return self.current
  12.  
  13.     def read(self, blocksize):
  14.         req = self.session.get(self.url, headers={'Range': 'bytes=%s-%s'%(self.current, self.current+blocksize-1)})
  15.         self.current += blocksize
  16.         return req.content
  17.  
  18.     def seek(self, offset):
  19.         self.current = offset
  20.  
  21. if __name__ == '__main__':
  22.     obj = PDownload('https://dimonb.com/.torrents/qqq.tar')
  23.     tar = tarfile.TarFile(fileobj=obj)
  24.     print tar.getmembers()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement