X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;f=bin%2Funzip.py;h=a5d3cf35e20ab4f41d670fd4965233388d388897;hb=05cfb307e205fea010f32eda0c3944ffc40b6775;hp=6eb4832dc91efa9ef35dcc1786d663ce958602f4;hpb=f7c63cf4c6268dce1643f15c72964495db8f72b3;p=dotfiles.git diff --git a/bin/unzip.py b/bin/unzip.py index 6eb4832..a5d3cf3 100755 --- a/bin/unzip.py +++ b/bin/unzip.py @@ -6,6 +6,7 @@ import sys, os, time from getopt import getopt, GetoptError +from shutil import copyfileobj from zipfile import ZipFile from m_lib.defenc import default_encoding @@ -13,11 +14,11 @@ def usage(): sys.exit('Usage: %s file.zip' % sys.argv[0]) try: - options, arguments = getopt(sys.argv[1:], '') + options, arguments = getopt(sys.argv[1:], '') except GetoptError: usage() -if len(arguments) <> 1: +if len(arguments) != 1: usage() zf = ZipFile(arguments[0], 'r') @@ -40,9 +41,11 @@ for zinfo in zf.infolist(): os.makedirs(tgtdir) if not tgt.endswith('/'): + infile = zf.open(zinfo.filename) fp = open(tgt, 'wb') - fp.write(zf.read(zinfo.filename)) + copyfileobj(infile, fp) fp.close() + infile.close() dt = time.mktime(zinfo.date_time + (0, 0, -1)) os.utime(tgt, (dt, dt)) zf.close()