All Projects → ShoshinNikita → go-disk-buffer

ShoshinNikita / go-disk-buffer

Licence: MIT license
This package helps to work with huge amount of data, which cannot be stored in RAM

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to go-disk-buffer

Write
Write data to the file system, creating any intermediate directories if they don't already exist. Used by flat-cache and many others!
Stars: ✭ 68 (+74.36%)
Mutual labels:  disk, buffer
retrocache
This library provides an easy way for configure retrofit for use a 2 layer cache (RAM and Disk)
Stars: ✭ 35 (-10.26%)
Mutual labels:  ram, disk
webpack-plugin-ramdisk
🐏 A webpack plugin for blazing fast builds on a RAM disk / drive
Stars: ✭ 118 (+202.56%)
Mutual labels:  ram, disk
Advanced-xv6
Modern improvements for MIT's xv6 OS
Stars: ✭ 26 (-33.33%)
Mutual labels:  disk
node-disk-utility
Quickly calculate the size of a folder or disk on macOS and Linux
Stars: ✭ 28 (-28.21%)
Mutual labels:  disk
NALib
General purpose C sourcecode collection
Stars: ✭ 16 (-58.97%)
Mutual labels:  buffer
Pulse
❤️ A heart rate camera pulse detector written in Swift.
Stars: ✭ 53 (+35.9%)
Mutual labels:  buffer
Volatility
An advanced memory forensics framework
Stars: ✭ 5,042 (+12828.21%)
Mutual labels:  ram
ember-validated-form-buffer
A validated form buffer that wraps Ember Data models for use in forms.
Stars: ✭ 46 (+17.95%)
Mutual labels:  buffer
SharpDiskSweeper
Reveal outstanding files or folders that are eating up your disk space
Stars: ✭ 21 (-46.15%)
Mutual labels:  disk
kvstore
KVStore is a simple Key-Value Store based on B+Tree (disk & memory) for Java
Stars: ✭ 88 (+125.64%)
Mutual labels:  disk
rn-bundles-demo
📱 react-native multi bundles demo
Stars: ✭ 17 (-56.41%)
Mutual labels:  ram
overflow
A command-line tool for exploiting stack-based buffer overflow vulnerabilities.
Stars: ✭ 66 (+69.23%)
Mutual labels:  buffer
ETurntable
ETurntable
Stars: ✭ 17 (-56.41%)
Mutual labels:  disk
RingBuffer
模仿 kfifo 实现的环形缓冲区
Stars: ✭ 64 (+64.1%)
Mutual labels:  buffer
Streamsaver.js
StreamSaver writes stream to the filesystem directly asynchronous
Stars: ✭ 2,784 (+7038.46%)
Mutual labels:  ram
WebServer
High-performance multi-threaded tcp network server in c++11
Stars: ✭ 58 (+48.72%)
Mutual labels:  buffer
SystemMonitor
Python script and a PyQt5 program to monitor ram and cpu usage along with disk usage.
Stars: ✭ 22 (-43.59%)
Mutual labels:  disk
sarviewer
Generate graphs with gnuplot or matplotlib (Python) from sar data
Stars: ✭ 60 (+53.85%)
Mutual labels:  ram
memtester
Simple memory tester mirror from http://pyropus.ca/software/memtester/. Please note that I am not the author of Memtester
Stars: ✭ 84 (+115.38%)
Mutual labels:  ram

Go Disk Buffer

Package buffer helps to work with huge amount of data, which cannot be stored in RAM. Instead of keeping all data in RAM buffer.Buffer can store the data on a disk in a temporary file.

Features:

  • buffer.Buffer is compatible with io.Reader and io.Writer interfaces
  • buffer.Buffer can replace bytes.Buffer (except some methods – check Unavailable methods)
  • You can encrypt data on a disk. Just use Buffer.EnableEncryption method

Notes:

  • It is not recommended to use zero value of buffer.Buffer. Use buffer.NewBuffer() or buffer.NewBufferWithMaxMemorySize() instead
  • buffer.Buffer is not thread-safe!
  • buffer.Buffer uses a directory returned by os.TempDir() to store temp files. You can change the directory with Buffer.ChangeTempDir method

Example

With bytes.Buffer

package main

import (
    "bytes"
    "fmt"
)

func main() {
    b := bytes.Buffer{}
    // b := bytes.NewBuffer(nil)
    // b := bytes.NewBufferString("")

    b.Write([]byte("Hello,"))
    b.WriteByte(' ')
    b.Write([]byte("World!"))

    data := b.Next(13)
    fmt.Println(string(data)) // "Hello, World!"
}

With github.com/ShoshinNikita/go-disk-buffer.Buffer

package main

import (
    "fmt"

    buffer "github.com/ShoshinNikita/go-disk-buffer"
)

func main() {
    b := buffer.NewBufferWithMaxMemorySize(7) // store only 7 bytes in RAM
    // b := buffer.NewBuffer(nil)
    // b := buffer.NewBufferString("")

    b.Write([]byte("Hello,"))
    b.WriteByte(' ')
    b.Write([]byte("World!")) // will be stored on a disk in a temporary file

    data := b.Next(13)
    fmt.Println(string(data)) // "Hello, World!"
}

Benchmark

CPU: Intel Core i7-3630QM
RAM: 8 GB
Disk: HDD, 5400 rpm

Buffer_size_is_greater_than_data/bytes.Buffer-8     1000       1591091 ns/op      10043209 B/op     36 allocs/op
Buffer_size_is_greater_than_data/utils.Buffer-8     1000       1346077 ns/op       6901679 B/op     26 allocs/op

Buffer_size_is_equal_to_data/bytes.Buffer-8         1000       1760100 ns/op      10043195 B/op     36 allocs/op
Buffer_size_is_equal_to_data/utils.Buffer-8         2000       1357077 ns/op       7434159 B/op     27 allocs/op

Buffer_size_is_less_than_data/bytes.Buffer-8          50      36522090 ns/op     177848123 B/op     53 allocs/op
Buffer_size_is_less_than_data/utils.Buffer-8          10     110406320 ns/op     112327659 B/op     62 allocs/op

Available methods

Read

  • Read(p []byte) (n int, err error)
  • ReadByte() (byte, error)
  • Next(n int) []byte
  • WriteTo(w io.Writer) (n int64, err error)

Write

  • Write(p []byte) (n int, err error)
  • WriteByte(c byte) error
  • WriteRune(r rune) (n int, err error)
  • WriteString(s string) (n int, err error)
  • ReadFrom(r io.Reader) (n int64, err error)

Other

  • Len() int
  • Cap() int – equal to Len() method
  • Reset()

Unavailable methods

Can be added

  • ReadBytes(delim byte) (line []byte, err error)
  • ReadString(delim byte) (line string, err error)
  • ReadRune() (r rune, size int, err error)help wanted (check Buffer.readRune() method)

Won't be adeed

  • Bytes() []byte

    Reason: go-disk-buffer was created to store a huge amount of data. If your data can fit in RAM, you should use bytes.Buffer

  • String() string

    Reason: see the previous reason

  • Grow(n int)

    Reason: we can allocate the memory only in RAM. It doesn't make sense to allocate space on a disk

  • Truncate(n int)

  • UnreadByte() error

  • UnreadRune() error

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].