Server IP : 103.119.228.120 / Your IP : 18.220.200.197 Web Server : Apache System : Linux v8.techscape8.com 3.10.0-1160.119.1.el7.tuxcare.els2.x86_64 #1 SMP Mon Jul 15 12:09:18 UTC 2024 x86_64 User : nobody ( 99) PHP Version : 5.6.40 Disable Function : shell_exec,symlink,system,exec,proc_get_status,proc_nice,proc_terminate,define_syslog_variables,syslog,openlog,closelog,escapeshellcmd,passthru,ocinum cols,ini_alter,leak,listen,chgrp,apache_note,apache_setenv,debugger_on,debugger_off,ftp_exec,dl,dll,myshellexec,proc_open,socket_bind,proc_close,escapeshellarg,parse_ini_filepopen,fpassthru,exec,passthru,escapeshellarg,escapeshellcmd,proc_close,proc_open,ini_alter,popen,show_source,proc_nice,proc_terminate,proc_get_status,proc_close,pfsockopen,leak,apache_child_terminate,posix_kill,posix_mkfifo,posix_setpgid,posix_setsid,posix_setuid,dl,symlink,shell_exec,system,dl,passthru,escapeshellarg,escapeshellcmd,myshellexec,c99_buff_prepare,c99_sess_put,fpassthru,getdisfunc,fx29exec,fx29exec2,is_windows,disp_freespace,fx29sh_getupdate,fx29_buff_prepare,fx29_sess_put,fx29shexit,fx29fsearch,fx29ftpbrutecheck,fx29sh_tools,fx29sh_about,milw0rm,imagez,sh_name,myshellexec,checkproxyhost,dosyayicek,c99_buff_prepare,c99_sess_put,c99getsource,c99sh_getupdate,c99fsearch,c99shexit,view_perms,posix_getpwuid,posix_getgrgid,posix_kill,parse_perms,parsesort,view_perms_color,set_encoder_input,ls_setcheckboxall,ls_reverse_all,rsg_read,rsg_glob,selfURL,dispsecinfo,unix2DosTime,addFile,system,get_users,view_size,DirFiles,DirFilesWide,DirPrintHTMLHeaders,GetFilesTotal,GetTitles,GetTimeTotal,GetMatchesCount,GetFileMatchesCount,GetResultFiles,fs_copy_dir,fs_copy_obj,fs_move_dir,fs_move_obj,fs_rmdir,SearchText,getmicrotime MySQL : ON | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /usr/lib64/python2.7/Demo/zlib/ |
Upload File : |
#! /usr/bin/env python # Demo program for zlib; it compresses or decompresses files, but *doesn't* # delete the original. This doesn't support all of gzip's options. # # The 'gzip' module in the standard library provides a more complete # implementation of gzip-format files. import zlib, sys, os FTEXT, FHCRC, FEXTRA, FNAME, FCOMMENT = 1, 2, 4, 8, 16 def write32(output, value): output.write(chr(value & 255)) ; value=value // 256 output.write(chr(value & 255)) ; value=value // 256 output.write(chr(value & 255)) ; value=value // 256 output.write(chr(value & 255)) def read32(input): v = ord(input.read(1)) v += (ord(input.read(1)) << 8 ) v += (ord(input.read(1)) << 16) v += (ord(input.read(1)) << 24) return v def compress (filename, input, output): output.write('\037\213\010') # Write the header, ... output.write(chr(FNAME)) # ... flag byte ... statval = os.stat(filename) # ... modification time ... mtime = statval[8] write32(output, mtime) output.write('\002') # ... slowest compression alg. ... output.write('\377') # ... OS (=unknown) ... output.write(filename+'\000') # ... original filename ... crcval = zlib.crc32("") compobj = zlib.compressobj(9, zlib.DEFLATED, -zlib.MAX_WBITS, zlib.DEF_MEM_LEVEL, 0) while True: data = input.read(1024) if data == "": break crcval = zlib.crc32(data, crcval) output.write(compobj.compress(data)) output.write(compobj.flush()) write32(output, crcval) # ... the CRC ... write32(output, statval[6]) # and the file size. def decompress (input, output): magic = input.read(2) if magic != '\037\213': print 'Not a gzipped file' sys.exit(0) if ord(input.read(1)) != 8: print 'Unknown compression method' sys.exit(0) flag = ord(input.read(1)) input.read(4+1+1) # Discard modification time, # extra flags, and OS byte. if flag & FEXTRA: # Read & discard the extra field, if present xlen = ord(input.read(1)) xlen += 256*ord(input.read(1)) input.read(xlen) if flag & FNAME: # Read and discard a null-terminated string containing the filename while True: s = input.read(1) if s == '\0': break if flag & FCOMMENT: # Read and discard a null-terminated string containing a comment while True: s=input.read(1) if s=='\0': break if flag & FHCRC: input.read(2) # Read & discard the 16-bit header CRC decompobj = zlib.decompressobj(-zlib.MAX_WBITS) crcval = zlib.crc32("") length = 0 while True: data=input.read(1024) if data == "": break decompdata = decompobj.decompress(data) output.write(decompdata) length += len(decompdata) crcval = zlib.crc32(decompdata, crcval) decompdata = decompobj.flush() output.write(decompdata) length += len(decompdata) crcval = zlib.crc32(decompdata, crcval) # We've read to the end of the file, so we have to rewind in order # to reread the 8 bytes containing the CRC and the file size. The # decompressor is smart and knows when to stop, so feeding it # extra data is harmless. input.seek(-8, 2) crc32 = read32(input) isize = read32(input) if crc32 != crcval: print 'CRC check failed.' if isize != length: print 'Incorrect length of data produced' def main(): if len(sys.argv)!=2: print 'Usage: minigzip.py <filename>' print ' The file will be compressed or decompressed.' sys.exit(0) filename = sys.argv[1] if filename.endswith('.gz'): compressing = False outputname = filename[:-3] else: compressing = True outputname = filename + '.gz' input = open(filename, 'rb') output = open(outputname, 'wb') if compressing: compress(filename, input, output) else: decompress(input, output) input.close() output.close() if __name__ == '__main__': main()