finish adding zip-crc (semi-streaming)

This commit is contained in:
ed 2021-03-27 01:27:12 +01:00
parent 426687b75e
commit 13e5c96cab
3 changed files with 24 additions and 11 deletions

View file

@ -1104,7 +1104,7 @@ class HttpCli(object):
fgen = vn.zipgen(rem, items, self.uname, dots, not self.args.no_scandir) fgen = vn.zipgen(rem, items, self.uname, dots, not self.args.no_scandir)
# for f in fgen: print(repr({k: f[k] for k in ["vp", "ap"]})) # for f in fgen: print(repr({k: f[k] for k in ["vp", "ap"]}))
bgen = packer(fgen, utf8="utf" in uarg) bgen = packer(fgen, utf8="utf" in uarg, pre_crc="crc" in uarg)
bsent = 0 bsent = 0
for buf in bgen.gen(): for buf in bgen.gen():
if not buf: if not buf:

View file

@ -1,10 +1,9 @@
import os
import time import time
import zlib import zlib
import struct import struct
from datetime import datetime from datetime import datetime
from .util import fsenc from .util import yieldfile
def dostime2unix(buf): def dostime2unix(buf):
@ -195,19 +194,23 @@ class StreamZip(object):
sz = st.st_size sz = st.st_size
ts = st.st_mtime + 1 ts = st.st_mtime + 1
crc = 0
if self.pre_crc:
crc = 0
for buf in yieldfile(src):
crc = zlib.crc32(buf, crc)
crc &= 0xFFFFFFFF
h_pos = self.pos h_pos = self.pos
buf = gen_hdr(None, name, sz, ts, self.utf8, None, self.pre_crc) buf = gen_hdr(None, name, sz, ts, self.utf8, None, self.pre_crc)
yield self._ct(buf) yield self._ct(buf)
crc = 0 for buf in yieldfile(src):
with open(fsenc(src), "rb", 512 * 1024) as f: if not self.pre_crc:
while True:
buf = f.read(64 * 1024)
if not buf:
break
crc = zlib.crc32(buf, crc) crc = zlib.crc32(buf, crc)
yield self._ct(buf)
yield self._ct(buf)
crc &= 0xFFFFFFFF crc &= 0xFFFFFFFF

View file

@ -780,6 +780,16 @@ def read_socket_chunked(sr, log=None):
sr.recv(2) # \r\n after each chunk too sr.recv(2) # \r\n after each chunk too
def yieldfile(fn):
with open(fsenc(fn), "rb", 512 * 1024) as f:
while True:
buf = f.read(64 * 1024)
if not buf:
break
yield buf
def hashcopy(actor, fin, fout): def hashcopy(actor, fin, fout):
u32_lim = int((2 ** 31) * 0.9) u32_lim = int((2 ** 31) * 0.9)
hashobj = hashlib.sha512() hashobj = hashlib.sha512()