Skip to content

Commit

Permalink
add exmaple, add copy/license heading, improve the docs
Browse files Browse the repository at this point in the history
  • Loading branch information
logrusorgru committed Jun 1, 2016
1 parent a43069b commit 755c0f0
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 10 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ lifo
[![GoReportCard](http://goreportcard.com/badge/logrusorgru/lifo)](http://goreportcard.com/report/logrusorgru/lifo)
[![paypal donate](https://img.shields.io/badge/paypal%20%24-donate-orange.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=QN87HECD52E4Q)

golang lifo reader/writer buffer like truncated bytes.Buffer but lifo
Golang lifo reader/writer buffer like truncated bytes.Buffer. The LIFO
means part-by-part. If you write `[]byte("Hello")` and then `[]byte("World")`.
After that you can read it back: `"World"` then `"Hello"`.

### Install

Expand Down
37 changes: 28 additions & 9 deletions buffer.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,32 @@
// Package lifo implements bytes buffer with LIFO order (last-in-first-out)
//
// /* For exapmle: */
// b := NewBuffer(nil)
// b.WriteByte(byte(1))
// b.WriteByte(byte(2))
// b.WriteByte(byte(3))
// b.ReadByte // => 3
// b.ReadByte // => 2
// b.ReadByte // => 1
// Copyright (c) 2016 Konstanin Ivanov <kostyarin.ivanov@gmail.com>.
// All rights reserved. This program is free software. It comes without
// any warranty, to the extent permitted by applicable law. You can
// redistribute it and/or modify it under the terms of the Do What
// The Fuck You Want To Public License, Version 2, as published by
// Sam Hocevar. See LICENSE.md file for more details or see below.
//

//
// DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
// Version 2, December 2004
//
// Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
//
// Everyone is permitted to copy and distribute verbatim or modified
// copies of this license document, and changing it is allowed as long
// as the name is changed.
//
// DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
// TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
//
// 0. You just DO WHAT THE FUCK YOU WANT TO.
//

// Package lifo implements bytes buffer with LIFO order (last-in-first-out)
// part-by-part. So, if you write `[]byte("Hello")` and then
// `[]byte("World")`. After that you can read it back: `"World"`
// then `"Hello"`.
package lifo

import (
Expand Down
25 changes: 25 additions & 0 deletions buffer_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,28 @@
//
// Copyright (c) 2016 Konstanin Ivanov <kostyarin.ivanov@gmail.com>.
// All rights reserved. This program is free software. It comes without
// any warranty, to the extent permitted by applicable law. You can
// redistribute it and/or modify it under the terms of the Do What
// The Fuck You Want To Public License, Version 2, as published by
// Sam Hocevar. See LICENSE.md file for more details or see below.
//

//
// DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
// Version 2, December 2004
//
// Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
//
// Everyone is permitted to copy and distribute verbatim or modified
// copies of this license document, and changing it is allowed as long
// as the name is changed.
//
// DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
// TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
//
// 0. You just DO WHAT THE FUCK YOU WANT TO.
//

package lifo

import (
Expand Down
50 changes: 50 additions & 0 deletions example_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//
// Copyright (c) 2016 Konstanin Ivanov <kostyarin.ivanov@gmail.com>.
// All rights reserved. This program is free software. It comes without
// any warranty, to the extent permitted by applicable law. You can
// redistribute it and/or modify it under the terms of the Do What
// The Fuck You Want To Public License, Version 2, as published by
// Sam Hocevar. See LICENSE.md file for more details or see below.
//

//
// DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
// Version 2, December 2004
//
// Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
//
// Everyone is permitted to copy and distribute verbatim or modified
// copies of this license document, and changing it is allowed as long
// as the name is changed.
//
// DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
// TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
//
// 0. You just DO WHAT THE FUCK YOU WANT TO.
//

package lifo

import (
"fmt"
)

func Example_lifo() {
b := NewBuffer(nil)

b.Write([]byte("bye"))
b.Write([]byte("hello"))

hello := make([]byte, 5)
bye := make([]byte, 3)

b.Read(hello)
b.Read(bye)

fmt.Println(string(hello))
fmt.Println(string(bye))

// Output
// hello
// bye
}

0 comments on commit 755c0f0

Please sign in to comment.