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
35506135
Kaydet (Commit)
35506135
authored
Haz 03, 2006
tarafından
Andrew M. Kuchling
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Put code in a main() function; loosen up the spacing to match current code style
üst
3725dea9
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
32 deletions
+45
-32
zlibdemo.py
Demo/zlib/zlibdemo.py
+45
-32
No files found.
Demo/zlib/zlibdemo.py
Dosyayı görüntüle @
35506135
#!/usr/bin/env python
# Takes an optional filename, defaulting to this file itself.
# Reads the file and compresses the content using level 1 and level 9
# compression, printing a summary of the results.
import
zlib
,
sys
if
len
(
sys
.
argv
)
>
1
:
filename
=
sys
.
argv
[
1
]
else
:
filename
=
'zlibdemo.py'
print
'Reading'
,
filename
f
=
open
(
filename
,
'r'
)
# Get the data to compress
s
=
f
.
read
()
f
.
close
()
# First, we'll compress the string in one step
comptext
=
zlib
.
compress
(
s
,
1
)
decomp
=
zlib
.
decompress
(
comptext
)
print
'1-step compression: (level 1)'
print
' Original:'
,
len
(
s
),
'Compressed:'
,
len
(
comptext
),
print
'Uncompressed:'
,
len
(
decomp
)
# Now, let's compress the string in stages; set chunk to work in smaller steps
chunk
=
256
compressor
=
zlib
.
compressobj
(
9
)
decompressor
=
zlib
.
decompressobj
()
comptext
=
decomp
=
''
for
i
in
range
(
0
,
len
(
s
),
chunk
):
comptext
=
comptext
+
compressor
.
compress
(
s
[
i
:
i
+
chunk
])
comptext
=
comptext
+
compressor
.
flush
()
# Don't forget to call flush()!!
for
i
in
range
(
0
,
len
(
comptext
),
chunk
):
decomp
=
decomp
+
decompressor
.
decompress
(
comptext
[
i
:
i
+
chunk
])
decomp
=
decomp
+
decompressor
.
flush
()
print
'Progressive compression (level 9):'
print
' Original:'
,
len
(
s
),
'Compressed:'
,
len
(
comptext
),
print
'Uncompressed:'
,
len
(
decomp
)
def
main
():
if
len
(
sys
.
argv
)
>
1
:
filename
=
sys
.
argv
[
1
]
else
:
filename
=
sys
.
argv
[
0
]
print
'Reading'
,
filename
f
=
open
(
filename
,
'rb'
)
# Get the data to compress
s
=
f
.
read
()
f
.
close
()
# First, we'll compress the string in one step
comptext
=
zlib
.
compress
(
s
,
1
)
decomp
=
zlib
.
decompress
(
comptext
)
print
'1-step compression: (level 1)'
print
' Original:'
,
len
(
s
),
'Compressed:'
,
len
(
comptext
),
print
'Uncompressed:'
,
len
(
decomp
)
# Now, let's compress the string in stages; set chunk to work in smaller steps
chunk
=
256
compressor
=
zlib
.
compressobj
(
9
)
decompressor
=
zlib
.
decompressobj
()
comptext
=
decomp
=
''
for
i
in
range
(
0
,
len
(
s
),
chunk
):
comptext
=
comptext
+
compressor
.
compress
(
s
[
i
:
i
+
chunk
])
# Don't forget to call flush()!!
comptext
=
comptext
+
compressor
.
flush
()
for
i
in
range
(
0
,
len
(
comptext
),
chunk
):
decomp
=
decomp
+
decompressor
.
decompress
(
comptext
[
i
:
i
+
chunk
])
decomp
=
decomp
+
decompressor
.
flush
()
print
'Progressive compression (level 9):'
print
' Original:'
,
len
(
s
),
'Compressed:'
,
len
(
comptext
),
print
'Uncompressed:'
,
len
(
decomp
)
if
__name__
==
'__main__'
:
main
()
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