Created
December 26, 2018 17:13
-
-
Save bioshazard/8c46e4bec717f140d5d8579de7f77bec to your computer and use it in GitHub Desktop.
Read super large byte by byte. Useful for when logs are full of null byte or CRAZY long lines.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Read super large byte by byte. Useful for when logs are full of null byte or CRAZY long lines. | |
import time, sys | |
def readBytes(filename, stopAt=0): | |
# Byte by Byte | |
linecnt = 0 | |
charlist = [] | |
with open(filename, "rb") as f: | |
byte = f.read(1) | |
while byte != "": | |
# Do stuff with byte. | |
byte = f.read(1) | |
print(byte, type(byte), linecnt, charlist) | |
if byte not in charlist: | |
charlist.append(byte) | |
linecnt = linecnt + 1 | |
if stopAt > 0: | |
if stopAt < linecnt: | |
break | |
if len(sys.argv) < 2: | |
print('Error, requires filename at $1') | |
sys.exit(1) | |
filename = sys.argv[1] | |
readBytes(filename) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment