diff --git a/memfs.py b/memfs.py index 9146144bf..a2bb7c774 100755 --- a/memfs.py +++ b/memfs.py @@ -61,8 +61,6 @@ for directory in dirs: for dirpath, dirnames, files in os.walk(directory, followlinks=True): - - # Prune the walk by modifying the dirnames in-place dirnames[:] = [dirname for dirname in dirnames if dirname not in EXCLUDED] for name in files: @@ -90,7 +88,8 @@ for directory in dirs: FILES[name] = fname SIZES[name] = os.path.getsize(full) - buffer.write("const unsigned char %s[] = {" % (name,)) + txt = "const unsigned char %s[] = {" % (name,) + buffer.write(txt.encode()) with open(full, "rb") as f: i = 0 @@ -104,16 +103,18 @@ for directory in dirs: # e.g. 23 -> 0x23 for n in range(0, len(contents_hex), 2): twoChars = ascii(contents_hex[n : n + 2]) - buffer.write("0x%s," % (twoChars,)) + txt = "0x%s," % (twoChars,) + buffer.write(txt.encode()) i += 1 if (i % 20) == 0: - buffer.write("\n") + buffer.write("\n".encode()) - buffer.write("};\n") + buffer.write("};\n".encode()) if buffer.tell() >= CHUNK: buffer.close() buffer = None + if buffer is not None: buffer.close() @@ -317,4 +318,3 @@ FILE* codes_memfs_open(const char* path) { print("Finished") print("MEMFS: done", time.time() - start) -