From c0d8818b2000c2805517eb5ea7af5716fba63cdb Mon Sep 17 00:00:00 2001 From: Arthur Hanson Date: Wed, 28 Nov 2018 09:34:25 -0800 Subject: [PATCH 1/2] DD_MAGIC reversed --- zipstream/consts.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zipstream/consts.py b/zipstream/consts.py index 1c86fde..6823e2d 100644 --- a/zipstream/consts.py +++ b/zipstream/consts.py @@ -37,7 +37,7 @@ DD_STRUCT64 = struct.Struct(b" Date: Wed, 28 Nov 2018 09:42:38 -0800 Subject: [PATCH 2/2] allow streaming from URL --- zipstream/zipstream.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/zipstream/zipstream.py b/zipstream/zipstream.py index 047adf0..baea177 100644 --- a/zipstream/zipstream.py +++ b/zipstream/zipstream.py @@ -5,6 +5,7 @@ # import os import time +import urllib import zlib from . import consts @@ -113,6 +114,9 @@ def _create_file_struct(self, data): if 'file' in data: file_struct['src'] = data['file'] file_struct['stype'] = 'f' + elif 'url' in data: + file_struct['src'] = data['url'] + file_struct['stype'] = 'u' elif 'stream' in data: file_struct['src'] = data['stream'] file_struct['stype'] = 's' @@ -274,6 +278,14 @@ def data_generator(self, src, src_type): break yield part return + if src_type == 'u': + with urllib.request.urlopen(src) as fh: + while True: + part = fh.read(self.chunksize) + if not part: + break + yield part + return def _stream_single_file(self, file_struct): """