--- title: "Blosc Compression" output: rmarkdown::html_vignette vignette: > %\VignetteIndexEntry{Blosc Compression} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} --- ```{r, include = FALSE} knitr::opts_chunk$set( collapse = TRUE, comment = "#>", out.width = "50%", fig.width = 5, fig.height = 4 ) ``` ## Compress with Blosc ### Input data When your input data is of type `raw()`, it is assumed that it encodes a data type where each element is `typesize` bytes long. The data type can be any structured form of data and does not necessarily needs to be known. Of course you need to know the structure when you need to interpret the data, but that's not up to the Blosc compressor. The example below compresses the `raw()` data assuming that the data type is 2 bytes long. ```{r compress} library(blosc) data_input <- as.raw(c(1, 2, 3, 4, 1, 2, 3, 4)) blosc_compress(data_input, typesize = 2) ``` Note that the length of the resulting data is actually longer than that of the input data. This is because the compressor has an overhead. The data set is just too small compared to the overhead. Can you compress other data types with Blosc? Yes you can. You first have to encode it to a binary form (`raw()`), with for instance `r_to_dtype()` or any other method that converts your data into a `raw()` format. You can also use the `dtype` argument to encode and compress your data in one go. In that case you need to specify an appropriate data type (`vignette("dtypes")`). The example below shows how to encode `numeric()` values as little-endian 16 bit floating point data (`"