Package: remoteunrar
remoteunrarThis module provides a way to access single members of a zip file archive without downloading the full content from a remote web server. For this library to work, the web server hosting the archive needs to support therangeheader.Installationpip install remoteunrarUsageInitializationremoteunrar(url, ...)To download the content, this library rely on therequestsmodule. The constructor interface matches the functionrequests.getmodule.url: Url where the rar file is located(required).auth: authentication credentials.headers: headers to pass to the request.timeout: timeout for the request.verify: enable/disable certificate verification or set custom certificates location.... Please look at therequestsdocumentation for futher usage details.initial_buffer_size: How much data (in bytes) to fetch during the first connection to download the rar file central directory. If your zip file conteins a lot of files, would be a good idea to increase this parameter in order to avoid the need for further remote requests.Default: 64kb.Class Interfaceremoteunraris a subclass of the python standard library classzipfile.ZipFile, so it supports all its read methods:remoteunrar.close()remoteunrar.getinfo(name)remoteunrar.extract(member[, path[, pwd]])remoteunrar.extractall([path[, members[, pwd]]])remoteunrar.infolist()remoteunrar.namelist()remoteunrar.open(name[, mode[, pwd]])remoteunrar.printdir()remoteunrar.read(name[, pwd])remoteunrar.testzip()remoteunrar.filenameremoteunrar.debugremoteunrar.commentPlease look at thezipfiledocumentation for usage details.NOTE:extractall()andtestzip()require to access the full content of the archive. If you need to use such methods, a full download of it would be probably more efficient.ExamplesList members in archivePrint all members part of the archive:importremoteunrarwithremoteunrar('http://.../myfile.rar')asrar:forzip_infoinrar.infolist():print(zip_info.filename)Download a memberThe following example will extract the filesomefile.txtfrom the archive stored at the urlhttp://.../myfile.zip.importremoteunrarwithremoteunrar('http://.../myfile.rar')asrar:rar.extract('somefile.txt')S3 exampleIf you are trying to download a member from a rar archive hosted on S3 you can use theaws-requests-authlibrary for that as follow:fromaws_requests_auth.boto_utilsimportBotoAWSRequestsAuthfromhashlibimportsha256auth=BotoAWSRequestsAuth(aws_host='s3-eu-west-1.amazonaws.com',aws_region='eu-west-1',aws_service='s3')headers={'x-amz-content-sha256':sha256('').hexdigest()}url="https://s3-eu-west-1.amazonaws.com/.../file.rar"withremoteunrar(url,auth=auth,headers=headers)asz:rar.extract('somefile.txt')Command line toolA simple command line tool is included in this distribution.usage: remoteunrar [-h] [-l] [-d DIR] url [filename [filename ...]]

Unrar remote files

positional arguments:
  url                Url of the rar archive
  filename           File to extract

optional arguments:
  -h, --help         show this help message and exit
  -l, --list         List files in the archive
  -d DIR, --dir DIR  Extract directory, default current directoryExample$ remoteunrar -l "http://thematicmapping.org/downloads/TM_WORLD_BORDERS-0.3.rar"
  Length  DateTime             Name
--------  -------------------  ------------------------
    2962  2008-07-30 13:58:46  Readme.txt
   24740  2008-07-30 12:16:46  TM_WORLD_BORDERS-0.3.dbf
     145  2008-03-12 13:11:54  TM_WORLD_BORDERS-0.3.prj
 6478464  2008-07-30 12:16:46  TM_WORLD_BORDERS-0.3.shp
    2068  2008-07-30 12:16:46  TM_WORLD_BORDERS-0.3.shx
    
$ remoteunrar "http://thematicmapping.org/downloads/TM_WORLD_BORDERS-0.3.rar" Readme.txt
Extracting Readme.txt...How it worksThis module uses thezipfile.ZipFileclass under the hood to decode the zip file format. TheZipFileclass is initialized with a file like object that will perform transparently the remote queries.The rar format is composed by the content of each compressed member followed by the central directory.How many requests will this module perform to download a member?If the full archive content is smaller thaninitial_buffer_size, only one request will be needed.Normally two requests are needed, one to download the central directory and one to download the archive member.If the central directory is bigger thaninitial_buffer_size, a third request will be required.Alternative modulesThere is a similar module available for pythonpyremotezip.