import { Bits , Byte } from '../types' ; import writeByte from '../byte/write' ; import readBuffer from './read' ; example param { Buffer } buffer param { Array } bits param { Number } offset returns { undefined } export default ( buffer , bits , offset = 0 ) : void => { const start = Math . floor ( offset / 8 ) ; const end = Math . ceil ( ( offset + bits . length ) / 8 ) ; const subBuffer = buffer . slice ( start , end ) ; const byteData = readBuffer ( subBuffer ) ; let subOffset = offset % 8 ; for ( var i = 0 ; i < bits . length ; i ++ ) byteData [ subOffset ++ ] = bits [ i ] ; const length = end - start ; for ( let i = 0 ; i < length ; i ++ ) subBuffer [ i ] = writeByte ( < Byte > byteData . slice ( i * 8 , ( i + 1 ) * 8 ) ) ; } ;