Skip to content

Instantly share code, notes, and snippets.

@Fhernd
Created July 9, 2018 12:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Fhernd/844582a97c6d46a7b0b4d618db57ad15 to your computer and use it in GitHub Desktop.
Save Fhernd/844582a97c6d46a7b0b4d618db57ad15 to your computer and use it in GitHub Desktop.
Buffer mutable. OrtizOL.
import os.path
def leer_buffer(archivo):
b = bytearray(os.path.getsize(archivo))
with open(archivo, 'rb') as f:
f.readinto(b)
return b
with open('archivo.bin', 'wb') as f:
f.write(b'Homo Deus: una historia del manana')
b = leer_buffer('archivo.bin')
print(b)
print(b[0:4])
print(len(b))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment