Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
vision
Commits
b9a1984c
Unverified
Commit
b9a1984c
authored
Jun 19, 2023
by
Adam J. Stewart
Committed by
GitHub
Jun 19, 2023
Browse files
Simpler file chunking (#7673)
Co-authored-by:
Philip Meier
<
github.pmeier@posteo.de
>
parent
3d70e4bb
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
4 additions
and
14 deletions
+4
-14
packaging/wheel/relocate.py
packaging/wheel/relocate.py
+1
-11
torchvision/datasets/utils.py
torchvision/datasets/utils.py
+1
-1
torchvision/prototype/datasets/_builtin/README.md
torchvision/prototype/datasets/_builtin/README.md
+1
-1
torchvision/prototype/datasets/utils/_resource.py
torchvision/prototype/datasets/utils/_resource.py
+1
-1
No files found.
packaging/wheel/relocate.py
View file @
b9a1984c
...
...
@@ -2,7 +2,6 @@
import
glob
import
hashlib
import
io
# Standard library imports
import
os
...
...
@@ -65,21 +64,12 @@ PLATFORM_ARCH = platform.machine()
PYTHON_VERSION
=
sys
.
version_info
def
read_chunks
(
file
,
size
=
io
.
DEFAULT_BUFFER_SIZE
):
"""Yield pieces of data from a file-like object until EOF."""
while
True
:
chunk
=
file
.
read
(
size
)
if
not
chunk
:
break
yield
chunk
def
rehash
(
path
,
blocksize
=
1
<<
20
):
"""Return (hash, length) for path using hashlib.sha256()"""
h
=
hashlib
.
sha256
()
length
=
0
with
open
(
path
,
"rb"
)
as
f
:
for
block
in
read_chunks
(
f
,
size
=
blocksize
):
while
block
:
=
f
.
read
(
blocksize
):
length
+=
len
(
block
)
h
.
update
(
block
)
digest
=
"sha256="
+
urlsafe_b64encode
(
h
.
digest
()).
decode
(
"latin1"
).
rstrip
(
"="
)
...
...
torchvision/datasets/utils.py
View file @
b9a1984c
...
...
@@ -57,7 +57,7 @@ def calculate_md5(fpath: str, chunk_size: int = 1024 * 1024) -> str:
else
:
md5
=
hashlib
.
md5
()
with
open
(
fpath
,
"rb"
)
as
f
:
for
chunk
in
iter
(
lambda
:
f
.
read
(
chunk_size
)
,
b
""
)
:
while
chunk
:
=
f
.
read
(
chunk_size
):
md5
.
update
(
chunk
)
return
md5
.
hexdigest
()
...
...
torchvision/prototype/datasets/_builtin/README.md
View file @
b9a1984c
...
...
@@ -91,7 +91,7 @@ import hashlib
def
sha256sum
(
path
,
chunk_size
=
1024
*
1024
):
checksum
=
hashlib
.
sha256
()
with
open
(
path
,
"rb"
)
as
f
:
for
chunk
in
iter
(
lambda
:
f
.
read
(
chunk_size
)
,
b
""
)
:
while
chunk
:
=
f
.
read
(
chunk_size
):
checksum
.
update
(
chunk
)
print
(
checksum
.
hexdigest
())
```
...
...
torchvision/prototype/datasets/utils/_resource.py
View file @
b9a1984c
...
...
@@ -136,7 +136,7 @@ class OnlineResource(abc.ABC):
def
_check_sha256
(
self
,
path
:
pathlib
.
Path
,
*
,
chunk_size
:
int
=
1024
*
1024
)
->
None
:
hash
=
hashlib
.
sha256
()
with
open
(
path
,
"rb"
)
as
file
:
for
chunk
in
iter
(
lambda
:
file
.
read
(
chunk_size
)
,
b
""
)
:
while
chunk
:
=
file
.
read
(
chunk_size
):
hash
.
update
(
chunk
)
sha256
=
hash
.
hexdigest
()
if
sha256
!=
self
.
sha256
:
...
...
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