Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kisom/sbuf
Last synced: 18 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/kisom/sbuf
- Owner: kisom
- License: isc
- Created: 2015-01-17T08:21:30.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2016-11-23T01:39:14.000Z (almost 8 years ago)
- Last Synced: 2024-10-11T02:46:23.222Z (about 1 month ago)
- Language: Go
- Size: 6.84 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# sbuf
`import "github.com/kisom/sbuf"`**NB**: the canonical version of this is contained in
the [goutils](https://github.com/kisom/goutils) repository.* [Overview](#pkg-overview)
* [Index](#pkg-index)## Overview
Package sbuf implements a byte buffer that can be wiped. The
underlying byte slice is wiped on read before being declaimed, and
when the buffer is closed, its storage is zeroised. It is meant to be
a drop-in replacement
for [`bytes.Buffer`](https://golang.org/pkg/bytes/#Buffer).## Index
* [type Buffer](#Buffer)
* [func NewBuffer(n int) *Buffer](#NewBuffer)
* [func NewBufferFrom(p []byte) *Buffer](#NewBufferFrom)
* [func (buf *Buffer) Bytes() []byte](#Buffer.Bytes)
* [func (buf *Buffer) Cap() int](#Buffer.Cap)
* [func (buf *Buffer) Close()](#Buffer.Close)
* [func (buf *Buffer) Len() int](#Buffer.Len)
* [func (buf *Buffer) Read(p []byte) (int, error)](#Buffer.Read)
* [func (buf *Buffer) ReadByte() (byte, error)](#Buffer.ReadByte)
* [func (buf *Buffer) Write(p []byte) (int, error)](#Buffer.Write)
* [func (buf *Buffer) WriteByte(c byte) error](#Buffer.WriteByte)#### Package files
[sbuf.go](/src/target/sbuf.go)## type [Buffer](/src/target/sbuf.go?s=532:566#L15)
``` go
type Buffer struct {
// contains filtered or unexported fields
}
```
A Buffer is a variable-sized buffer of bytes with Read and Write
methods. The zero value for Buffer is an empty buffer ready to use.### func [NewBuffer](/src/target/sbuf.go?s=631:660#L20)
``` go
func NewBuffer(n int) *Buffer
```
NewBuffer creates a new buffer with the specified capacity.### func [NewBufferFrom](/src/target/sbuf.go?s=818:854#L28)
``` go
func NewBufferFrom(p []byte) *Buffer
```
NewBufferFrom creates a new buffer from the byte slice passed in. The
original data will be wiped.### func (\*Buffer) [Bytes](/src/target/sbuf.go?s=3012:3045#L125)
``` go
func (buf *Buffer) Bytes() []byte
```
Bytes returns the bytes currently in the buffer, and closes itself.### func (\*Buffer) [Cap](/src/target/sbuf.go?s=2886:2914#L120)
``` go
func (buf *Buffer) Cap() int
```
Cap returns the capacity of the buffer.### func (\*Buffer) [Close](/src/target/sbuf.go?s=2671:2697#L109)
``` go
func (buf *Buffer) Close()
```
Close destroys and zeroises the buffer. The buffer will be re-opened
on the next write.### func (\*Buffer) [Len](/src/target/sbuf.go?s=2788:2816#L115)
``` go
func (buf *Buffer) Len() int
```
Len returns the length of the buffer.### func (\*Buffer) [Read](/src/target/sbuf.go?s=1167:1213#L39)
``` go
func (buf *Buffer) Read(p []byte) (int, error)
```
Read reads the next len(p) bytes from the buffer or until the buffer
is drained. The return value n is the number of bytes read. If the
buffer has no data to return, err is io.EOF (unless len(p) is zero);
otherwise it is nil.### func (\*Buffer) [ReadByte](/src/target/sbuf.go?s=1614:1657#L60)
``` go
func (buf *Buffer) ReadByte() (byte, error)
```
ReadByte reads the next byte from the buffer. If the buffer has no
data to return, err is io.EOF; otherwise it is nil.### func (\*Buffer) [Write](/src/target/sbuf.go?s=2073:2120#L80)
``` go
func (buf *Buffer) Write(p []byte) (int, error)
```
Write appends the contents of p to the buffer, growing the buffer
as needed. The return value n is the length of p; err is always nil.### func (\*Buffer) [WriteByte](/src/target/sbuf.go?s=2396:2438#L97)
``` go
func (buf *Buffer) WriteByte(c byte) error
```
WriteByte adds the byte c to the buffer, growing the buffer as needed.- - -
Generated by [godoc2md](http://godoc.org/github.com/davecheney/godoc2md)