Socket
Book a DemoInstallSign in
Socket

vimagination.zapto.org/rwcount

Package Overview
Dependencies
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vimagination.zapto.org/rwcount

Go Modules
Version
v1.1.2
Version published
Created
Source

rwcount

CI Go Reference Go Report Card

-- import "vimagination.zapto.org/rwcount"

Package rwcount implements a simple counter that wraps an io.Reader or io.Writer.

Useful for functions (like binary.Read/Write) which do not return read/write counts.

Highlights

  • Wrap any io.Reader or io.Writer.
  • Keeps track of bytes read/written.
  • First error is stored and future reads/writes will all return that error.

Usage

package main

import (
	"bytes"
	"encoding/binary"
	"fmt"

	"vimagination.zapto.org/rwcount"
)

func main() {
	var (
		buf    bytes.Buffer
		result uint16
	)

	writer := &rwcount.Writer{Writer: &buf}

	binary.Write(writer, binary.LittleEndian, uint16(1234))

	reader := &rwcount.Reader{Reader: &buf}
	binary.Read(reader, binary.LittleEndian, &result)

	fmt.Printf("Wrote bytes: %d\n"+
		"Write error: %v\n"+
		"Read bytes: %d\n"+
		"Read error: %v\n"+
		"Read value: %d\n",
		writer.Count,
		writer.Err,
		reader.Count,
		reader.Err,
		result,
	)

	// Output:
	// Wrote bytes: 2
	// Write error: <nil>
	// Read bytes: 2
	// Read error: <nil>
	// Read value: 1234
}

Documentation

Full API docs can be found at:

https://pkg.go.dev/vimagination.zapto.org/rwcount

FAQs

Package last updated on 29 Sep 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts