Skip to content

Instantly share code, notes, and snippets.

@shiracamus
Created January 13, 2018 21:39
Show Gist options
  • Save shiracamus/e713e219c8c7d015a147916f7e984298 to your computer and use it in GitHub Desktop.
Save shiracamus/e713e219c8c7d015a147916f7e984298 to your computer and use it in GitHub Desktop.
def divide_file(filePath, chunkSize):
def read():
with open(filePath, 'rb') as f:
while True:
data = f.read(chunkSize)
if len(data) == 0:
return
yield data
def write(filePath, data):
with open(filePath, 'wb') as f:
f.write(data)
def divide():
for i, data in enumerate(read()):
saveFilePath = '%s.%s' % (filePath, i)
write(saveFilePath, data)
yield saveFilePath
return list(divide())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment