How to transform bitstring into iodata?

You’ll problably need to store the number of bits padded in the file as well, otherwise you won’t be able to reconstruct the original bitstring from the file.

Small example

t = <<3::size(17)>> 
# => <<0, 1, 1::size(1)>>
pad = 8 - (bit_size(t) - (bit_size(t) |> Integer.floor_div(8)) * 8)  
# => 7
<<t::bitstring, 0::size(pad)>>
# => <<0, 1, 128>>

but if that is stored directly to a file, there is no way of knowing how many bits were padded.
So a convention could be to take the first 8-bits to mean the amount of padding that needs
to be removed (as well as the number itself).