Created
July 4, 2018 04:54
-
-
Save armsp/c50977f9ab75b39ecffd05a32d9e9cc8 to your computer and use it in GitHub Desktop.
Resuming file uploads in flask
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import hashlib | |
full_file = 'isd-inventory.csv' | |
part_file = 'isd-inventory.csv.part' | |
m = hashlib.md5() | |
with open(full_file, 'rb') as f: | |
for chunk in iter(lambda: f.read(128*m.block_size), b''): | |
m.update(chunk) | |
print(m.hexdigest()) | |
m = hashlib.md5() | |
with open(part_file, 'rb') as f: | |
for chunk in iter(lambda: f.read(128*m.block_size), b''): | |
m.update(chunk) | |
print(m.hexdigest()) | |
with open(full_file, 'rb') as f: | |
print(f.tell()) | |
f.seek(0, 2) | |
print(f.tell()) | |
with open(part_file, 'rb') as f: | |
print(f.tell()) | |
f.seek(0, 2) | |
print(f.tell()) | |
with open(full_file, 'rb') as f: | |
f.seek(6619668, 0) | |
copy = f.read() | |
with open(part_file, 'ab') as f: | |
f.write(copy) | |
f.seek(0) | |
m = hashlib.md5() | |
with open(part_file, 'rb') as f: | |
for chunk in iter(lambda: f.read(128*m.block_size), b''): | |
m.update(chunk) | |
print(m.hexdigest()) | |
m = hashlib.md5() | |
with open(full_file, 'rb') as f: | |
for chunk in iter(lambda: f.read(128*m.block_size), b''): | |
m.update(chunk) | |
print(m.hexdigest()) | |
m = hashlib.md5() | |
with open('hello.txt', 'rb') as f: | |
for chunk in iter(lambda: f.read(128*m.block_size), b''): | |
m.update(chunk) | |
print(m.hexdigest()) | |
m = hashlib.md5() | |
with open('world.txt', 'rb') as f: | |
for chunk in iter(lambda: f.read(128*m.block_size), b''): | |
m.update(chunk) | |
print(m.hexdigest()) | |
with open('hello.txt', 'ab') as f: | |
f.seek(0,2) | |
k = f.tell() | |
with open('world.txt', 'rb') as fo: | |
fo.seek(k, 0) | |
c = fo.read() | |
f.write(c) | |
f.seek(0) | |
m = hashlib.md5() | |
with open('hello.txt', 'rb') as f: | |
for chunk in iter(lambda: f.read(128*m.block_size), b''): | |
m.update(chunk) | |
print(m.hexdigest()) | |
m = hashlib.md5() | |
with open('world.txt', 'rb') as f: | |
for chunk in iter(lambda: f.read(128*m.block_size), b''): | |
m.update(chunk) | |
print(m.hexdigest()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment