You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: iobitwriter.go
    path of file: ./repos/fq/pkg/bitio
    
    the code of the file until where you have to start completion: package bitio

import (
	"io"
)

// IOBitWriter is a bitio.Writer that writes to a io.Writer.
// Use Flush to write possible unaligned byte zero bit padded.
type IOBitWriter struct {
	w io.Writer
	b Buffer
}

// NewIOBitWriter returns a new bitio.IOBitWriter.
func NewIOBitWriter(w io.Writer) *IOBitWriter {
	return &IOBitWriter{w: w}
}

func (w *IOBitWriter) WriteBits(p []byte, nBits int64) (n int64, err error) {
	
    
func (w *IOBitWriter) WriteBits(p []byte, nBits int64) (n int64, err error) {
	if n, err = w.b.WriteBits(p, nBits); err != nil {
		return n, err
	}

	var sn int64

	for {
		l := w.b.Len()
		if l < 8 {
			break
		}

		var buf [32 * 1024]byte
		n, err := w.b.ReadBits(buf[:], l-(l%8))
		if err != nil {
			return sn, err
		}

		rn, err := w.w.Write(buf[:n/8])
		sn += int64(rn)
		if err != nil {
			return sn, err
		}

		sn += n
	}

	return nBits, nil
}