• Stars
    star
    216
  • Rank 183,179 (Top 4 %)
  • Language
    Go
  • License
    MIT License
  • Created about 9 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Asynchronous read-ahead for Go readers

readahead

Asynchronous read-ahead for Go readers

This package will allow you to add readhead to any reader. This means a separate goroutine will perform reads from your upstream reader, so you can request from this reader without delay.

This is helpful for splitting an input stream into concurrent processing, and also helps smooth out bursts of input or output.

This should be fully transparent, except that once an error has been returned from the Reader, it will not recover. A panic will be caught and returned as an error.

The readahead object also fulfills the io.WriterTo interface, which is likely to speed up io.Copy and other code that use the interface.

See an introduction: An Async Read-ahead Package for Go

Go Reference Go

usage

To get the package use go get -u github.com/klauspost/readahead.

Here is a simple example that does file copy. Error handling has been omitted for brevity.

input, _ := os.Open("input.txt")
output, _ := os.Create("output.txt")
defer input.Close()
defer output.Close()

// Create a read-ahead Reader with default settings
ra := readahead.NewReader(input)
defer ra.Close()

// Copy the content to our output
_, _ = io.Copy(output, ra)

settings

You can finetune the read-ahead for your specific use case, and adjust the number of buffers and the size of each buffer.

The default the size of each buffer is 1MB, and there are 4 buffers. Do not make your buffers too small since there is a small overhead for passing buffers between goroutines. Other than that you are free to experiment with buffer sizes.

contributions

On this project contributions in terms of new features is limited to:

  • Features that are widely usable and
  • Features that have extensive tests

This package is meant to be simple and stable, so therefore these strict requirements.

license

This package is released under the MIT license. See the supplied LICENSE file for more info.

More Repositories

1

compress

Optimized Go Compression Packages
Go
4,247
star
2

reedsolomon

Reed-Solomon Erasure Coding in Go
Assembly
1,728
star
3

pgzip

Go parallel gzip (de)compression
Go
1,045
star
4

cpuid

CPU feature identification for Go
Go
863
star
5

ryzen-master-vbs-patch

AMD Ryzen Master Hyper-V VBS patcher
Go
355
star
6

asmfmt

Go Assembler Formatter
Go
247
star
7

dedup

Streaming Deduplication Package for Go
Go
186
star
8

geoip-service

A fast in-memory http microservice for looking up MaxMind GeoIP2 and GeoLite2 database
Go
74
star
9

crc32

CRC32 hash with x64 optimizations
Go
73
star
10

rawspeed

Raw Image Decoder Library
C++
71
star
11

shutdown2

Shutdown Management package for Go v2
Go
49
star
12

password

Dictionary Password Validation for Go
Go
49
star
13

gad

Go After Dark
Go
40
star
14

shutdown

Shutdown management library for Go
Go
36
star
15

intrinsics

Experiment with Go intrinsics (NOT USABLE)
HTML
32
star
16

doproxy

Reverse Proxy for managing multiple Digital Ocean backends.
Go
30
star
17

oui

Library & Microservice for looking up manufacturers from MAC addresses.
Go
27
star
18

lctime

Finally, simple, familiar, locale-based datetime formatting.
Go
22
star
19

connect-compress

connect-go improved compression
Go
19
star
20

mman-win32

Automatically exported from code.google.com/p/mman-win32
C
10
star
21

match

Byte matching in Go
Assembly
10
star
22

gfx

Graphic Drawing Library
Go
9
star
23

bitset

Go Integer Bitset Generator
Go
4
star
24

shift

Fast bit shift helper
Go
3
star
25

simdjson-fuzz

Fuzzers and corpus for github.com/fwessels/simdjson-go
Go
3
star
26

json

Fork of the official Go JSON library that allows streaming indented output
Go
3
star
27

compress-fuzz

Fuzz data for the klauspost/compress package
Go
2
star
28

talks

Talks
Go
2
star
29

dawa

Go implementation of DAWA AWS Suite 4 (Danish Address Info)
Go
1
star