-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.Rmd
101 lines (72 loc) · 2.08 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
---
output: rmarkdown::github_document
---
`gzmem` : Better in memory compression/decompression
A partial resurrection of `Rcompression` for [this](http://stackoverflow.com/q/39707388/1457051).
The following functions are implemented:
- `mem_compress`: Compress a raw vector
- `mem_inflate`: Inflate a raw vector compressed
### TODO
- [ ] Rewrite in Rcpp
- [ ] Make inflation dynamic vs relying on guessed bufffer size
### Installation
```{r eval=FALSE}
devtools::install_git("https://gitlab.com/hrbrmstr/gzmem.git")
```
```{r echo=FALSE, message=FALSE, warning=FALSE, error=FALSE}
options(width=120)
```
```{r echo=TRUE, message=FALSE, warning=FALSE, error=FALSE}
library(gzmem)
library(magrittr)
# current verison
packageVersion("gzmem")
```
### Usage
This package contains functions to compress and decompress raw vectors in R using the [zlib library](https://zlib.net/).
It supports 3 different formats: gzip, zlib and raw. These formats all use the [deflate algorithm](https://en.wikipedia.org/wiki/DEFLATE) to compress the data, but differ in the headers and footers they wrap around the deflate compressed data:
- gzip has a 10 byte header and an 8 byte footer around the compressed data.
- zlib has a 2 byte header and a 4 byte footer around the compressed data.
- raw has no header or footer, and so is just the deflate compressed data.
For example:
```{r}
text <- "Hey, the room is getting smaller. No, it's not. *He's* getting *bigger*!"
```
Shows the following differences between all 3 formats:
```{r}
gzip <- text %>%
charToRaw() %>%
mem_compress(format = "gzip")
```
```{r,echo=F}
gzip
```
```{r}
zlib <- text %>%
charToRaw() %>%
mem_compress(format = "zlib")
```
```{r, echo=F}
zlib
```
```{r}
raw <- text %>%
charToRaw() %>%
mem_compress(format = "raw")
```
```{r, echo=F}
raw
```
These can then be decompressed by selecting the appropriate format:
```{r}
gzip %>%
mem_inflate(format = "gzip", 1024) %>%
rawToChar()
```
### Test Results
```{r echo=TRUE, message=FALSE, warning=FALSE, error=FALSE}
library(gzmem)
library(testthat)
date()
test_dir("tests/")
```