Skip to content

Instantly share code, notes, and snippets.

@bioshazard
Created December 26, 2018 17:13
Show Gist options
  • Save bioshazard/8c46e4bec717f140d5d8579de7f77bec to your computer and use it in GitHub Desktop.
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.
# 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