| // Copyright 2016 The Upspin Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style |
| // license that can be found in the LICENSE file. |
| |
| // Package internal provides some helpers used by packing implementations. |
| package internal |
| |
| // LazyBuffer is a []byte that is lazily (re-)allocated when its |
| // Bytes method is called. |
| type LazyBuffer []byte |
| |
| // Bytes returns a []byte that has length n. It re-uses the underlying |
| // LazyBuffer []byte if it is at least n bytes in length. |
| func (b *LazyBuffer) Bytes(n int) []byte { |
| if *b == nil || len(*b) < n { |
| *b = make([]byte, n) |
| } |
| return (*b)[:n] |
| } |