Deprecate commit-mode (#697)

Rather than checking the json file to make sure posts have been
successfully downloaded, data is stored in a temporary file which
is renamed when downloading has finished, as suggested in #257.
This commit is contained in:
Lars Lindqvist
2020-06-20 16:23:31 +02:00
committed by GitHub
parent 66b3ec6928
commit fa62025ea3
3 changed files with 11 additions and 52 deletions

View File

@@ -1,5 +1,6 @@
import hashlib
import json
import os
import pickle
import random
import re
@@ -547,11 +548,12 @@ class InstaloaderContext:
.. versionadded:: 4.2.1"""
self.log(filename, end=' ', flush=True)
with open(filename, 'wb') as file:
with open(filename + '.temp', 'wb') as file:
if isinstance(resp, requests.Response):
shutil.copyfileobj(resp.raw, file)
else:
file.write(resp)
os.rename(filename + '.temp', filename)
def get_raw(self, url: str, _attempt=1) -> requests.Response:
"""Downloads a file anonymously.