Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
fb3b12d0
Kaydet (Commit)
fb3b12d0
authored
14 years ago
tarafından
Georg Brandl
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Make minigzip work again.
üst
5ec5fed4
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
21 deletions
+22
-21
minigzip.py
Demo/zlib/minigzip.py
+22
-21
No files found.
Demo/zlib/minigzip.py
Dosyayı görüntüle @
fb3b12d0
...
...
@@ -10,10 +10,10 @@ 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
))
output
.
write
(
bytes
([
value
&
255
]
))
;
value
=
value
//
256
output
.
write
(
bytes
([
value
&
255
]
))
;
value
=
value
//
256
output
.
write
(
bytes
([
value
&
255
]
))
;
value
=
value
//
256
output
.
write
(
bytes
([
value
&
255
]
))
def
read32
(
input
):
v
=
ord
(
input
.
read
(
1
))
...
...
@@ -22,23 +22,24 @@ def read32(input):
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 ...
def
compress
(
filename
,
input
,
output
):
output
.
write
(
b
'
\037\213\010
'
)
# Write the header, ...
output
.
write
(
bytes
([
FNAME
]))
# ... flag byte ...
statval
=
os
.
stat
(
filename
)
# ... modification time ...
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 ...
output
.
write
(
b
'
\002
'
)
# ... slowest compression alg. ...
output
.
write
(
b
'
\377
'
)
# ... OS (=unknown) ...
bfilename
=
filename
.
encode
(
sys
.
getfilesystemencoding
())
output
.
write
(
bfilename
+
b
'
\000
'
)
# ... original filename ...
crcval
=
zlib
.
crc32
(
""
)
crcval
=
zlib
.
crc32
(
b
''
)
compobj
=
zlib
.
compressobj
(
9
,
zlib
.
DEFLATED
,
-
zlib
.
MAX_WBITS
,
zlib
.
DEF_MEM_LEVEL
,
0
)
while
True
:
data
=
input
.
read
(
1024
)
if
data
==
""
:
if
data
==
b
''
:
break
crcval
=
zlib
.
crc32
(
data
,
crcval
)
output
.
write
(
compobj
.
compress
(
data
))
...
...
@@ -46,9 +47,9 @@ def compress (filename, input, output):
write32
(
output
,
crcval
)
# ... the CRC ...
write32
(
output
,
statval
[
6
])
# and the file size.
def
decompress
(
input
,
output
):
def
decompress
(
input
,
output
):
magic
=
input
.
read
(
2
)
if
magic
!=
'
\037\213
'
:
if
magic
!=
b
'
\037\213
'
:
print
(
'Not a gzipped file'
)
sys
.
exit
(
0
)
if
ord
(
input
.
read
(
1
))
!=
8
:
...
...
@@ -66,21 +67,21 @@ def decompress (input, output):
# Read and discard a null-terminated string containing the filename
while
True
:
s
=
input
.
read
(
1
)
if
s
==
'
\0
'
:
break
if
s
==
b
'
\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
s
=
input
.
read
(
1
)
if
s
==
b
'
\0
'
:
break
if
flag
&
FHCRC
:
input
.
read
(
2
)
# Read & discard the 16-bit header CRC
decompobj
=
zlib
.
decompressobj
(
-
zlib
.
MAX_WBITS
)
crcval
=
zlib
.
crc32
(
""
)
crcval
=
zlib
.
crc32
(
b
''
)
length
=
0
while
True
:
data
=
input
.
read
(
1024
)
if
data
==
""
:
data
=
input
.
read
(
1024
)
if
data
==
b
""
:
break
decompdata
=
decompobj
.
decompress
(
data
)
output
.
write
(
decompdata
)
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment