An open API service indexing awesome lists of open source software.

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

Awesome Lists containing this project

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://img.shields.io/badge/cool-useless-green.svg)
[![CRAN](https://www.r-pkg.org/badges/version/lz4lite)](https://cran.r-project.org/package=lz4lite)
[![R-CMD-check](https://github.com/coolbutuseless/lz4lite/actions/workflows/R-CMD-check.yaml/badge.svg)](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")

```