take bytes out of things easily ✨🍪

Overview

cookie with a bite taken out of it
crunch

a library for easily manipulating bits and bytes in golang

license godoc travis codecov go report card try it on repl.it

features | installation | benchmarks | examples

features

  • feature-rich: supports reading and writing integers of varying sizes in both little and big endian
  • performant: performs more than twice as fast as the standard library's bytes.Buffer
  • simple and familiar: has a consistent and easy-to-use api
  • licensed under the mpl-2.0: use it anywhere you wish, just don't change it privately

installation

install with the go tool

$ go get github.com/superwhiskers/crunch/v3

then, just import it in your project like this. easy!

package "yourpackage"

import crunch "github.com/superwhiskers/crunch/v3"

install using git submodules (not recommended)

# this assumes that you are in a git repository
$ git submodule add https://github.com/superwhiskers/crunch path/to/where/you/want/crunch

then, you can import it like this

package "yourpackage"

import crunch "github.com/your-username/project/path/to/crunch/v3"

benchmarks

both Buffer and MiniBuffer perform on average more than twice as fast as bytes.Buffer in both writing and reading

BenchmarkBufferWriteBytes-4             2000000000               1.45 ns/op            0 B/op          0 allocs/op
BenchmarkBufferReadBytes-4              2000000000               0.84 ns/op            0 B/op          0 allocs/op
BenchmarkBufferWriteU32LE-4             200000000                9.28 ns/op            0 B/op          0 allocs/op
BenchmarkBufferReadU32LE-4              50000000                26.6 ns/op             8 B/op          1 allocs/op
BenchmarkBufferReadBit-4                2000000000               0.84 ns/op            0 B/op          0 allocs/op
BenchmarkBufferReadBits-4               1000000000               2.25 ns/op            0 B/op          0 allocs/op
BenchmarkBufferSetBit-4                 1000000000               2.07 ns/op            0 B/op          0 allocs/op
BenchmarkBufferClearBit-4               1000000000               2.05 ns/op            0 B/op          0 allocs/op
BenchmarkMiniBufferWriteBytes-4         2000000000               1.42 ns/op            0 B/op          0 allocs/op
BenchmarkMiniBufferReadBytes-4          2000000000               0.58 ns/op            0 B/op          0 allocs/op
BenchmarkMiniBufferWriteU32LE-4         200000000                8.79 ns/op            0 B/op          0 allocs/op
BenchmarkMiniBufferReadU32LE-4          500000000                3.91 ns/op            0 B/op          0 allocs/op
BenchmarkMiniBufferReadBit-4            2000000000               0.64 ns/op            0 B/op          0 allocs/op
BenchmarkMiniBufferReadBits-4           300000000                5.64 ns/op            0 B/op          0 allocs/op
BenchmarkMiniBufferSetBit-4             1000000000               2.03 ns/op            0 B/op          0 allocs/op
BenchmarkMiniBufferClearBit-4           1000000000               2.10 ns/op            0 B/op          0 allocs/op
BenchmarkStdByteBufferWrite-4           200000000                9.42 ns/op            0 B/op          0 allocs/op
BenchmarkStdByteBufferRead-4            500000000                3.36 ns/op            0 B/op          0 allocs/op

examples

examples can be found in the examples directory

acknowledgements

icon (cookie logo) made by freepik from flaticon.com

You might also like...
An IPFS bytes exchange for caching and retrieving data from Filecoin

🐸 go-hop-exchange An IPFS bytes exchange to allow any IPFS node to become a Filecoin retrieval provider and retrieve content from Filecoin Highlights

A tiny date object in Go. Tinydate uses only 4 bytes of memory

go-tinydate A tiny date object in Go. Tinydate uses 4 bytes of memory vs the 24 bytes of a standard time.Time{} A tinydate only has day precision. It

Segment tree for bytes in Go

bsegtree Segment tree for bytes in Go Based on Thomas Oberndörfer's int range segment tree with fixing/optimization/modification for bytes ranges. For

PKSUID is a small extension for KSUID (K-Sortable Globally Unique IDs) which allows prefixing it with arbitrary up to 16 bytes strings

PKSUID is a small extension for KSUID (K-Sortable Globally Unique IDs) which allows prefixing it with arbitrary up to 16 bytes strings

A utility library to do files/io/bytes processing/parsing in file-system or network.

goreader A utility library to do files/io/bytes processing/parsing in file-system or network. These features are really common to be implemented for a

Encode (structured and unstructured) data via bytes

Go Bytes Go A simple encoding lib to print/parse structured and unstructured data over a non self-describing bytestream. This lib will use the include

File-generator - Creates a file filled with bytes

creates a file filled with bytes ./filegen from to from : index of first piece t

A logr LogSink implementation using bytes.Buffer

buflogr A logr LogSink implementation using bytes.Buffer. Usage import ( "bytes" "fmt" "github.com/go-logr/logr" "github.com/tonglil/buflogr" )

A small drunken bishop written in Go to represent bytes.

Go, Little Drunken Bishop! go get github.com/eloonstra/go-little-drunken-bishop Table of Contents How does it work? Usage Example License Contributin

Print random bytes from a secure source to stdout.

Print random bytes from a secure source to stdout.

A Go library that provides functions for bytes and bits.

Byteman A Golang library that provides functions for bytes and bits. Usage See byteman_test.go, numbers_test.go and strings_test.go. Test # Test every

A Go package to allow you to read and write from the serial port as a stream of bytes.

Serial A Go package to allow you to read and write from the serial port as a stream of bytes. Details It aims to have the same API on all platforms, i

Take control of your data, connect with anything, and expose it anywhere through protocols such as HTTP, GraphQL, and gRPC.
Take control of your data, connect with anything, and expose it anywhere through protocols such as HTTP, GraphQL, and gRPC.

Semaphore Chat: Discord Documentation: Github pages Go package documentation: GoDev Take control of your data, connect with anything, and expose it an

Demonstrating how you can take an action to your intrusions detected by Falco using OpenFaaS functions
Demonstrating how you can take an action to your intrusions detected by Falco using OpenFaaS functions

Kubernetes Response Engine powered by OpenFaaS Although Falco can be used to detect any intrusion attempts and sends alerts to channels according to t

Take screenshots of websites and create PDF from HTML pages using chromium and docker

gochro is a small docker image with chromium installed and a golang based webserver to interact wit it. It can be used to take screenshots of w

Take a list of domains and scan for endpoints, secrets, api keys, file extensions, tokens and more...
Take a list of domains and scan for endpoints, secrets, api keys, file extensions, tokens and more...

Take a list of domains and scan for endpoints, secrets, api keys, file extensions, tokens and more... Coded with 💙 by edoardottt. Share on Twitter! P

Take an IP address and quickly get the reverse PTR

FlipIP Just a little quick app to take an IP (or set of IPs), and convert them to reverse IP pointers Example: $ flipip 1.2.3.4 4.3.2.1.in-addr.arpa.

Cook amazing genetic parts using our cookbook. Recipes and synthetic biology tools to take your breath away.

friendzymes-cookbook Friendly tools for a friendly community. A collection of tutorials and genetic tools for synthetic biology. This cookbook is a su

A simple CLI app to take notes daily on markdown file
A simple CLI app to take notes daily on markdown file

A simple CLI app to take notes daily on markdown file

Comments
  •  Fix misuse of unsafe.Pointer in buffer.go

    Fix misuse of unsafe.Pointer in buffer.go

    According to: https://golang.org/pkg/unsafe/#Pointer

    Usage of unsafe.Pointer should be implemented with defined pattern to avoid becoming invalid in the future.

    opened by LaevusDexter 1
  • Fix misuse of unsafe.Pointer in minibuf.go

    Fix misuse of unsafe.Pointer in minibuf.go

    According to: https://golang.org/pkg/unsafe/#Pointer

    Usage of unsafe.Pointer should be implemented with defined pattern to avoid becoming invalid in the future.

    opened by LaevusDexter 1
Releases(v3.5.6)
  • v3.5.6(Feb 9, 2022)

    crunch :cookie: v3.5.6

    a quick release to swap the old goto-loop style WriteBytes methods for a newer copy-based method body to improve performance, once again bringing write times consistently underneath 3ns

    Source code(tar.gz)
    Source code(zip)
  • v3.5.5(Aug 7, 2021)

  • v3.5.4(Jan 22, 2021)

  • v3.5.2(Jan 22, 2021)

  • v3.5.1(Apr 30, 2020)

    crunch :cookie: v3.5.1

    probably the last release in a while. i should test more and run stuff more before releasing like that

    changes

    • fix comment generation for *Next methods
    • make linter happy
    • format code
    • remove todo comments that are no longer necessary
    • test against 1.14.x
    Source code(tar.gz)
    Source code(zip)
  • v3.5.0(Apr 30, 2020)

  • v3.4.0(Apr 22, 2020)

    crunch :cookie: v3.4.0

    changes

    • signed integer support
    • all SNEN methods are generated by code and not written by hand. updates may come faster now as i no longer need to break my hands to add in new read/write methods

    things that didn't change

    • code coverage. still at 100%
    Source code(tar.gz)
    Source code(zip)
  • v3.3.1(Mar 15, 2020)

  • v3.3.0(Jan 28, 2020)

  • v3.2.0(Oct 9, 2019)

  • v3.1.0(Aug 23, 2019)

    crunch :cookie: v3.1.0

    changes

    • added TruncateLeft and TruncateRight for shrinking the buffer on both the left and right ends
    • sped up the Grow method some more
    • misc. other fixes and improvements
    Source code(tar.gz)
    Source code(zip)
  • v3.0.0(May 31, 2019)

    crunch :cookie: v3.0.0

    changes

    • misc. improvements to speed in some parts
    • more code cleanup (massive restructure of the source to be cleaner)
    • remove proxy functions (functions that just execute private functions on the buffer types)
    • more benchmarks
    • more???
    Source code(tar.gz)
    Source code(zip)
  • v2.0.0(May 27, 2019)

    crunch :cookie: v2.0.0

    changes

    • full redo of how ComplexRead and ComplexWrite work
    • numerous speed improvements to bit-related functions
    • code cleanup
    • tests, tests, and more tests
    • more speed improvements
    • and more!
    Source code(tar.gz)
    Source code(zip)
  • v1.0.0(Apr 6, 2019)

    crunch :cookie: v1.0.0

    features

    • MiniBuffer and Buffer feature parity
    • MiniBuffer is faster than bytes.Buffer
    • reading and writing of uint8/uint16/uint32/uint64-s with ComplexRead and ComplexWrite
    • 100% test coverage
    • Buffer is safe for concurrent usage
    • and much, much more

    enjoy!

    Source code(tar.gz)
    Source code(zip)
Owner
superwhiskers
superwhiskers
Simple code just to try out and Binary Tree on Golang.

Character counter | ▮▮▮▮▮▮▮▮ Simple code just to try out and Binary Tree on Golang. Count characters to train openning a file and reading it, as well

Arthur Abeilice 0 May 17, 2022
TBH, there are probably better/faster implementations out there.

Scott's Skiplist TBH, there are probably better/faster implementations out there. See https://github.com/MauriceGit/skiplist-survey I wrote this one b

Scott White 1 Feb 10, 2022
parse and generate XML easily in go

etree The etree package is a lightweight, pure go package that expresses XML in the form of an element tree. Its design was inspired by the Python Ele

Brett Vickers 1k Dec 30, 2022
Time struct in Go that uses 4 bytes of memory vs the 24 bytes of time.Time

A tiny time object in Go. Tinytime uses 4 bytes of memory vs the 24 bytes of a standard time.Time{}

Lane Wagner 59 Oct 3, 2022
Take control over your live stream video by running it yourself. Streaming + chat out of the box.

Take control over your content and stream it yourself. Explore the docs » View Demo · Use Our Server for Testing · FAQ · Report Bug Table of Contents

Owncast 6.8k Jan 1, 2023
Fonts is a package that provides helpers to access font details and easily retrive font bytes with ZERO dependencies

Fonts Fonts is a package that provides helpers to access font details and easily retrieve font bytes. This package has ZERO 3rd-party dependencies. Fo

Go Swiss 10 Mar 3, 2022
Easily and securely send things from one computer to another :crocodile: :package:

This project is supported by: croc is a tool that allows any two computers to simply and securely transfer files and folders. AFAIK, croc is the only

Zack 21.5k Jan 3, 2023
In 'n Out - See what goes in and comes out of PEs/DLLs

In 'n Out Parse and return PE information ino -v comsvcs.dll { "Name": "<string>", "Path": "<string>", "Type": "<string file|directory>", "Im

Alex Flores 28 Dec 16, 2022
Issue-mafia - An out-of-the-box CLI that helps you to easily synchronize Git hooks with a remote repository

issue-mafia is an out-of-the-box CLI that helps you to easily synchronize Git hooks with a remote repository.

Thiago 0 Feb 14, 2022
yq lets you read YAML files easily on the terminal. You can find key/values easily

yq yq lets you read YAML files easily on the terminal. You can find key/values easily. Motivation Reading yaml configurations for k8s file becomes ard

Farhan 3 Nov 2, 2021