File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import time
22import string
33import zlib
4+ import struct
45import __builtin__
56
67# implements a python function that reads and writes a gzipped file
1415READ , WRITE = 1 , 2
1516
1617def write32 (output , value ):
17- t = divmod (value , 256 )
18- b1 = chr (t [1 ])
19-
20- t = divmod (t [0 ], 256 )
21- b2 = chr (t [1 ])
22-
23- t = divmod (t [0 ], 256 )
24- b3 = chr (t [1 ])
25-
26- t = divmod (t [0 ], 256 )
27- b4 = chr (t [1 ])
28-
29- buf = b1 + b2 + b3 + b4
30- output .write (buf )
31-
18+ output .write (struct .pack ("<l" , value ))
3219
3320def read32 (input ):
34- buf = input .read (4 )
35- v = ord (buf [0 ])
36- v = v + (ord (buf [1 ]) << 8 )
37- v = v + (ord (buf [2 ]) << 16 )
38- v = v + (ord (buf [3 ]) << 24 )
39- return v
21+ return struct .unpack ("<l" , input .read (4 ))[0 ]
4022
4123def open (filename , mode = "r" , compresslevel = 9 ):
4224 return GzipFile (filename , mode , compresslevel )
You can’t perform that action at this time.
0 commit comments