Skip to content

Latest commit

 

History

History
50 lines (34 loc) · 1.7 KB

README.md

File metadata and controls

50 lines (34 loc) · 1.7 KB

bufio fork: writer buffer injection

godoc - documentation go report card github action - test codecov - code coverage

A fork of Go's standard bufio package, adding support for buffer injected writers.

Installation

go get -u github.com/ahmedabdou14/bufio

Usage

package main

import (
    "os"

    "github.com/ahmedabdou14/bufio"
)

func main() {
    file, err := os.Create("test.txt")
    if err != nil {
        panic(err)
    }
    defer file.Close()

    buf := make([]byte, 10) 
    
    w := bufio.NewWriterBuffer(file, buf)
    w.WriteString("Hello, World!")
    w.Flush() 
}

Why?

Only use this package if you need the fine-grained control over the buffers used by the writer. One use case is when you want to reuse buffers for multiple writers and somewhere else in your code. For more details, checkout this issue

Maybe you do not need this package, in most usecases, you would only need to reuse the writers themselves, not the buffers. For more details, checkout this issue

Warning ⚠️

Be carful of using the buffer after passing it to the writer. Doings so will result in unexpected behavior.