github.com/jjjabc/fitsio@v0.0.0-20161215022839-d1807e9e818e/buffer.go (about)

     1  // Copyright 2015 The astrogo Authors.  All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package fitsio
     6  
     7  import (
     8  	"fmt"
     9  )
    10  
    11  type sectionWriter struct {
    12  	buf []byte
    13  	beg int
    14  }
    15  
    16  func (w *sectionWriter) Write(p []byte) (n int, err error) {
    17  	n = copy(w.buf[w.beg:], p)
    18  	if n < len(p) {
    19  		return n, fmt.Errorf("fitsio: wrote %d bytes. expected %d", n, len(p))
    20  	}
    21  	w.beg += n
    22  	return
    23  }