import { Bits , Byte } from '../types' ; import writeByte from '../byte/write' ; example param { Array } bits returns { Buffer } export default ( bits ) : Buffer => { const data = [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ; const buffer = Buffer . alloc ( Math . ceil ( bits . length / 8 ) ) ; for ( let i = 0 ; i < buffer . length ; i ++ ) { for ( let j = 0 ; j < 8 ; j ++ ) { if ( bits [ i * 8 + j ] ) data [ j ] = bits [ i * 8 + j ] ; else data [ j ] = 0 ; } buffer [ i ] = writeByte ( data ) ; } return buffer ; } ;