Skip to content

Instantly share code, notes, and snippets.

@armsp
Created July 4, 2018 04:54
Show Gist options
  • Save armsp/c50977f9ab75b39ecffd05a32d9e9cc8 to your computer and use it in GitHub Desktop.
Save armsp/c50977f9ab75b39ecffd05a32d9e9cc8 to your computer and use it in GitHub Desktop.
Resuming file uploads in flask
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