Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE
/
storagedriver
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
2
Merge Requests
4
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
A prog2-höz tartozó friss repo anyagok itt elérhetőek:
https://git.iit.bme.hu/
Commit
6462577a
authored
Mar 01, 2014
by
Őry Máté
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add zlib + bz2 support to Disk.download
parent
67c57436
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
1 deletions
+14
-1
disk.py
+14
-1
No files found.
disk.py
View file @
6462577a
...
...
@@ -5,6 +5,8 @@ import re
import
logging
from
shutil
import
move
,
copyfileobj
from
zipfile
import
ZipFile
,
is_zipfile
from
zlib
import
decompressobj
,
MAX_WBITS
from
bz2
import
BZ2Decompressor
import
requests
...
...
@@ -122,11 +124,21 @@ class Disk(object):
percent
=
0
actual_size
=
0
chunk_size
=
256
*
1024
ext
=
url
.
split
(
'.'
)[
-
1
]
.
lower
()
if
ext
==
'gz'
:
decompressor
=
decompressobj
(
16
+
MAX_WBITS
)
# undocumented zlib feature http://stackoverflow.com/a/2424549
elif
ext
==
'bz2'
:
decompressor
=
BZ2Decompressor
()
clen
=
max
(
int
(
r
.
headers
.
get
(
'content-length'
,
700000000
)),
1
)
percent
=
0
try
:
with
open
(
disk_path
,
'wb'
)
as
f
:
for
chunk
in
r
.
iter_content
(
chunk_size
=
chunk_size
):
if
task
.
is_aborted
():
raise
AbortException
()
if
ext
in
(
'gz'
,
'bz'
):
chunk
=
decompressor
.
decompress
(
chunk
)
if
chunk
:
f
.
write
(
chunk
)
actual_size
+=
chunk_size
...
...
@@ -137,6 +149,8 @@ class Disk(object):
state
=
task
.
AsyncResult
(
parent_id
)
.
state
,
meta
=
{
'size'
:
actual_size
,
'percent'
:
percent
})
if
ext
==
'gz'
:
f
.
write
(
decompressor
.
flush
())
f
.
flush
()
self
.
size
=
os
.
path
.
getsize
(
disk_path
)
logger
.
debug
(
"Download finished
%
s (
%
s bytes)"
,
...
...
@@ -152,7 +166,6 @@ class Disk(object):
url
,
disk_path
)
raise
else
:
ext
=
url
.
split
(
'.'
)[
-
1
]
.
lower
()
if
ext
==
'zip'
and
is_zipfile
(
disk_path
):
task
.
update_state
(
task_id
=
parent_id
,
...
...
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