Skip to content

hinohi/bitio

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

bitio

Utilities to read or write files by bit or bits

Install

pip install bitio

Usage

from bitio import bit_open

f = bit_open(file_name, "r")
x = f.read()           # return 1 or 0
x = f.read_bits(count) # return int

f = bit_open(file_name, "w")
f.write(bit)              # write 1 if bit else 0
f.write_bits(bits, count) # write 'count bits'
f.close()

These are the same

f.write_bits(bits, count)

for i in range(count-1, -1, -1):
  if bits & (1 << i):
    f.write(1)
  else:
    f.write(0)

Another interface

l = []
wrapper = ByteWrapper(l.append)
f = bit_wrap(wrapper, "w")
f.write_bits(0b110000101, 10)
print(l)    # [b"a"]
f.close()
print(l)    # [b"a", b"@"]

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages