https://github.com/coolbutuseless/lz4lite
Very Fast compression/decompression of in-memory numeric vectors with LZ4
https://github.com/coolbutuseless/lz4lite
Last synced: 3 months ago
JSON representation
Very Fast compression/decompression of in-memory numeric vectors with LZ4
- Host: GitHub
- URL: https://github.com/coolbutuseless/lz4lite
- Owner: coolbutuseless
- License: other
- Created: 2020-06-16T10:12:12.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2025-05-24T00:16:38.000Z (5 months ago)
- Last Synced: 2025-05-24T00:31:26.367Z (5 months ago)
- Language: C
- Homepage:
- Size: 146 KB
- Stars: 20
- Watchers: 3
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.Rmd
- Changelog: NEWS.md
- License: LICENSE
Awesome Lists containing this project
- jimsghstars - coolbutuseless/lz4lite - Very Fast compression/decompression of in-memory numeric vectors with LZ4 (C)
README
---
output: github_document
---```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = FALSE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)library(dplyr)
library(lz4lite)
```# lz4lite

[](https://cran.r-project.org/package=lz4lite)
[](https://github.com/coolbutuseless/lz4lite/actions/workflows/R-CMD-check.yaml)`lz4lite` provides access to the extremely fast compression in [lz4](https://github.com/lz4/lz4)
for performing in-memory compression of any R ojbect.`lz4` code provided with this package is v1.10.0.
### What's in the box
* **For arbitrary R objects**
* `lz4_serialize()`/`lz4_unserialize()` serialize and compress any R object.
* **For raw vectors**
* `lz4_compress()`/`lz4_decompress()`## Installation
You can install the latest development version from
[GitHub](https://github.com/coolbutuseless/lz4lite) with:``` r
# install.package('remotes')
remotes::install_github('coolbutuseless/lz4lite')
```Pre-built source/binary versions can also be installed from
[R-universe](https://r-universe.dev)``` r
install.packages('lz4lite', repos = c('https://coolbutuseless.r-universe.dev', 'https://cloud.r-project.org'))
```## Basic usage of lz4lite
```{r}
buf <- lz4_serialize(penguins)
length(buf) # Number of bytes# compression ratio
length(buf)/length(serialize(penguins, NULL))head(lz4_unserialize(buf))
```## Benchmark
```{r}
dat <- penguins[sample(nrow(penguins), 10000, T), ]
tmp <- tempfile()res <- bench::mark(
lz4lite::lz4_serialize(dat, tmp),
saveRDS(dat, tmp, compress = FALSE),
saveRDS(dat, tmp, compress = 'gzip'),
saveRDS(dat, tmp, compress = 'bzip2'),
saveRDS(dat, tmp, compress = 'xz'),
check = FALSE
)res[, 1:5] |>
knitr::kable(caption = "Time to serialize data and write to file")```