tmark 'blockchain_headers' file as sparse on windows - electrum - Electrum Bitcoin wallet HTML git clone https://git.parazyd.org/electrum DIR Log DIR Files DIR Refs DIR Submodules --- DIR commit cedd518aead91916ae68f96261908986a2a7909b DIR parent 855a70bc6612669138a7f927d7cde9c894a3aab6 HTML Author: SomberNight <somber.night@protonmail.com> Date: Wed, 19 Sep 2018 22:09:54 +0200 mark 'blockchain_headers' file as sparse on windows based on fyookball/electrum@647a6cc26dfe2d0d942159207c6e72e1b0e8d94d Diffstat: M electrum/network.py | 3 ++- M electrum/util.py | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) --- DIR diff --git a/electrum/network.py b/electrum/network.py t@@ -675,9 +675,10 @@ class Network(PrintError): length = 80 * len(constants.net.CHECKPOINTS) * 2016 if not os.path.exists(filename) or os.path.getsize(filename) < length: with open(filename, 'wb') as f: - if length>0: + if length > 0: f.seek(length-1) f.write(b'\x00') + util.ensure_sparse_file(filename) with b.lock: b.update_size() DIR diff --git a/electrum/util.py b/electrum/util.py t@@ -383,6 +383,16 @@ def android_check_data_dir(): return data_dir +def ensure_sparse_file(filename): + # On modern Linux, no need to do anything. + # On Windows, need to explicitly mark file. + if os.name == "nt": + try: + os.system('fsutil sparse setflag "{}" 1'.format(filename)) + except Exception as e: + print_error('error marking file {} as sparse: {}'.format(filename, e)) + + def get_headers_dir(config): return android_headers_dir() if 'ANDROID_DATA' in os.environ else config.path