def write(self, filename, arcname=None, compress_type=None):
if not self.fp:<EOL><INDENT>raise RuntimeError(<EOL>"<STR_LIT>")<EOL><DEDENT>st = os.stat(filename)<EOL>isdir = stat.S_ISDIR(st.st_mode)<EOL>mtime = time.localtime(st.st_mtime)<EOL>date_time = mtime[<NUM_LIT:0>:<NUM_LIT:6>]<EOL>if arcname is None:<EOL><INDENT>arcname = filename<EOL><DEDENT>arcname = os.path.normpath(os.path.splitdrive(arcname)[<NUM_LIT:1>])<EOL>while arcname[<NUM_LIT:0>] in (os.sep, os.altsep):<EOL><INDENT>arcname = arcname[<NUM_LIT:1>:]<EOL><DEDENT>if isdir:<EOL><INDENT>arcname += '<STR_LIT:/>'<EOL><DEDENT>zinfo = ZipInfo(arcname, date_time)<EOL>zinfo.external_attr = (st[<NUM_LIT:0>] & <NUM_LIT>) << <NUM_LIT:16>      <EOL>if compress_type is None:<EOL><INDENT>zinfo.compress_type = self.compression<EOL><DEDENT>else:<EOL><INDENT>zinfo.compress_type = compress_type<EOL><DEDENT>zinfo.file_size = st.st_size<EOL>zinfo.flag_bits = <NUM_LIT><EOL>zinfo.header_offset = self.fp.tell()    <EOL>self._writecheck(zinfo)<EOL>self._didModify = True<EOL>if isdir:<EOL><INDENT>zinfo.file_size = <NUM_LIT:0><EOL>zinfo.compress_size = <NUM_LIT:0><EOL>zinfo.CRC = <NUM_LIT:0><EOL>self.filelist.append(zinfo)<EOL>self.NameToInfo[zinfo.filename] = zinfo<EOL>self.fp.write(zinfo.FileHeader())<EOL>return<EOL><DEDENT>with open(filename, "<STR_LIT:rb>") as fp:<EOL><INDENT>zinfo.CRC = CRC = <NUM_LIT:0><EOL>zinfo.compress_size = compress_size = <NUM_LIT:0><EOL>zinfo.file_size = file_size = <NUM_LIT:0><EOL>self.fp.write(zinfo.FileHeader())<EOL>if zinfo.compress_type == ZIP_DEFLATED:<EOL><INDENT>cmpr = zlib.compressobj(zlib.Z_DEFAULT_COMPRESSION,<EOL>zlib.DEFLATED, -<NUM_LIT:15>)<EOL><DEDENT>else:<EOL><INDENT>cmpr = None<EOL><DEDENT>while <NUM_LIT:1>:<EOL><INDENT>buf = fp.read(<NUM_LIT> * <NUM_LIT:8>)<EOL>if not buf:<EOL><INDENT>break<EOL><DEDENT>file_size = file_size + len(buf)<EOL>CRC = crc32(buf, CRC) & <NUM_LIT><EOL>if cmpr:<EOL><INDENT>buf = cmpr.compress(buf)<EOL>compress_size = compress_size + len(buf)<EOL><DEDENT>self.fp.write(buf)<EOL><DEDENT><DEDENT>if cmpr:<EOL><INDENT>buf = cmpr.flush()<EOL>compress_size = compress_size + len(buf)<EOL>self.fp.write(buf)<EOL>zinfo.compress_size = compress_size<EOL><DEDENT>else:<EOL><INDENT>zinfo.compress_size = file_size<EOL><DEDENT>zinfo.CRC = CRC<EOL>zinfo.file_size = file_size<EOL>position = self.fp.tell()       <EOL>self.fp.seek(zinfo.header_offset + <NUM_LIT>, <NUM_LIT:0>)<EOL>self.fp.write(struct.pack("<STR_LIT>", zinfo.CRC, zinfo.compress_size,<EOL>zinfo.file_size))<EOL>self.fp.seek(position, <NUM_LIT:0>)<EOL>self.filelist.append(zinfo)<EOL>self.NameToInfo[zinfo.filename] = zinfo<EOL>
Put the bytes from filename into the archive under the name
        arcname.