Compare commits
5 Commits
Author | SHA1 | Date |
---|---|---|
|
45d2ae5a20 | 1 year ago |
|
ec372e8a62 | 1 year ago |
|
ebb80ce95f | 2 years ago |
|
92126e65be | 3 years ago |
|
203d00fca0 | 3 years ago |
@ -0,0 +1,9 @@ |
||||
image: alpine/edge |
||||
packages: |
||||
- go |
||||
sources: |
||||
- https://git.sr.ht/~lenzj/chunkio |
||||
tasks: |
||||
- test: | |
||||
cd chunkio |
||||
go test |
@ -1,71 +0,0 @@ |
||||
.POSIX: |
||||
|
||||
PNAME = chunkio
|
||||
|
||||
RTEMPLATE ?= ../repo-template
|
||||
|
||||
all: doc mkFile |
||||
|
||||
doc: docMain |
||||
|
||||
cleanDoc: cleanDocMain |
||||
|
||||
.DEFAULT_GOAL := all
|
||||
|
||||
.PHONY: all doc cleanDoc |
||||
|
||||
#---Golang Library Section---
|
||||
|
||||
GO ?= go
|
||||
GOFLAGS ?=
|
||||
GOSRC != find . -name '*.go'
|
||||
|
||||
check: $(GOSRC) |
||||
$(GO) test $(GOFLAGS)
|
||||
|
||||
.PHONY: check |
||||
|
||||
#---Generate Main Documents---
|
||||
|
||||
DOCMAIN := README.md LICENSE
|
||||
|
||||
README.md: template/README.md.got |
||||
pgot -i ":$(RTEMPLATE)" -o $@ $<
|
||||
|
||||
LICENSE: $(RTEMPLATE)/LICENSE.src/BSD-2-clause.got |
||||
pgot -i ":$(RTEMPLATE)" -o $@ $<
|
||||
|
||||
docMain: $(DOCMAIN) |
||||
|
||||
cleanDocMain: |
||||
$(RM) $(DOCMAIN)
|
||||
|
||||
.PHONY: docMain, cleanDocMain |
||||
|
||||
#---Generate Makefile---
|
||||
|
||||
Makefile: template/Makefile.got |
||||
pgot -i ":$(RTEMPLATE)" -o $@ $<
|
||||
|
||||
mkFile: Makefile |
||||
|
||||
regenMkFile: |
||||
pgot -i ":$(RTEMPLATE)" -o Makefile template/Makefile.got
|
||||
|
||||
.PHONY: mkFile regenMkFile |
||||
|
||||
#---Lint Helper Target---
|
||||
|
||||
lint: |
||||
@find . -path ./.git -prune -or \
|
||||
-type f -and -not -name 'Makefile' \
|
||||
-exec grep -Hn '<no value>' '{}' ';'
|
||||
|
||||
#---TODO Helper Target---
|
||||
|
||||
todo: |
||||
@find . -path ./.git -prune -or \
|
||||
-type f -and -not -name 'Makefile' \
|
||||
-exec grep -Hn TODO '{}' ';'
|
||||
|
||||
# vim:set noet tw=80:
|
@ -1,39 +0,0 @@ |
||||
;;; |
||||
{ |
||||
"pgotInclude" : [
|
||||
"global.got",
|
||||
"Makefile.src/mk-goLib.got",
|
||||
"Makefile.src/mk-docMain.got",
|
||||
"Makefile.src/mk-mkFile.got",
|
||||
"Makefile.src/mk-lint.got",
|
||||
"Makefile.src/mk-todo.got"
|
||||
]
|
||||
} |
||||
;;; |
||||
.POSIX: |
||||
|
||||
PNAME = chunkio
|
||||
|
||||
RTEMPLATE ?= ../repo-template
|
||||
|
||||
all: doc mkFile |
||||
|
||||
doc: docMain |
||||
|
||||
cleanDoc: cleanDocMain |
||||
|
||||
.DEFAULT_GOAL := all
|
||||
|
||||
.PHONY: all doc cleanDoc |
||||
|
||||
{{template "mk-goLib" .}} |
||||
|
||||
{{template "mk-docMain" .}} |
||||
|
||||
{{template "mk-mkFile" .}} |
||||
|
||||
{{template "mk-lint" .}} |
||||
|
||||
{{template "mk-todo" .}} |
||||
|
||||
# vim:set noet tw=80:
|
@ -1,95 +0,0 @@ |
||||
;;; |
||||
{ |
||||
"rname": "chunkio", |
||||
"pgotInclude": [ "README.src/all.got" ] |
||||
} |
||||
;;; |
||||
# {{.rname}} |
||||
|
||||
**{{.rname}}** is a golang package that provides functionality for transparently |
||||
reading a subset of a stream containing a user defined ending byte sequence. |
||||
When the byte sequence is reached an EOF is returned. This sub stream can be |
||||
accessed or passed to other routines as standard Reader objects. |
||||
|
||||
## Interface |
||||
|
||||
###Variables |
||||
|
||||
```text |
||||
var ErrInvalidKey = errors.New("{{.rname}}: invalid key definition") |
||||
``` |
||||
|
||||
###Types |
||||
|
||||
```text |
||||
type Reader struct { |
||||
// Has unexported fields. |
||||
} |
||||
Reader implements {{.rname}} functionality wrapped around an io.Reader object |
||||
|
||||
func NewReader(rd io.Reader) *Reader |
||||
NewReader creates a new chunk reader |
||||
|
||||
func (c *Reader) GetErr() error |
||||
GetErr returns the error status for the current active {{.rname}} stream |
||||
|
||||
func (c *Reader) GetKey() []byte |
||||
GetKey returns the key for the current active {{.rname}} stream |
||||
|
||||
func (c *Reader) Read(p []byte) (int, error) |
||||
Read implements the standard Reader interface allowing {{.rname}} to be used |
||||
anywhere a standard Reader can be used. Read reads data into p. It returns |
||||
the number of bytes read into p. The bytes are taken from at most one Read |
||||
on the underlying Reader, hence n may be less than len(p). When the key is |
||||
reached (EOF for the stream chunk), the count will be zero and err will be |
||||
io.EOF. If the key has been set to nil, the Read function performs exactly |
||||
like the underlying stream Read function (no key scanning). |
||||
|
||||
func (c *Reader) Reset() |
||||
Reset puts the {{.rname}} stream back into a readable state. This can be used |
||||
when the end of a chunk is reached to enable reading the next chunk. |
||||
|
||||
func (c *Reader) SetKey(key []byte) error |
||||
SetKey updates the search key. The search key can also be cleared by |
||||
providing a nil key. |
||||
``` |
||||
|
||||
## Example usage. |
||||
|
||||
```go |
||||
import ( |
||||
"bytes" |
||||
"fmt" |
||||
"io/ioutil" |
||||
"git.lenzplace.org/lenzj/{{.rname}}" |
||||
"strings" |
||||
) |
||||
|
||||
func ExampleUppercase() { |
||||
example := []byte("the quick {U}brown fox jumps{R} over the lazy dog") |
||||
cio := {{.rname}}.NewReader(bytes.NewReader(example)) |
||||
cio.SetKey([]byte("{U}")) |
||||
s1, _ := ioutil.ReadAll(cio) |
||||
cio.Reset() |
||||
cio.SetKey([]byte("{R}")) |
||||
s2, _ := ioutil.ReadAll(cio) |
||||
cio.Reset() |
||||
s3, _ := ioutil.ReadAll(cio) |
||||
fmt.Print(string(s1)+strings.ToUpper(string(s2))+string(s3)) |
||||
// Output: the quick BROWN FOX JUMPS over the lazy dog |
||||
} |
||||
``` |
||||
|
||||
## Running the tests |
||||
|
||||
``` |
||||
$ make check |
||||
``` |
||||
|
||||
{{template "rd-contributing" .}} |
||||
|
||||
{{template "rd-versioning" .}} |
||||
|
||||
{{template "rd-license" .}} |
||||
|
||||
<!-- vim:set ts=4 sw=4 et tw=80: --> |
Loading…
Reference in new issue