Skip to content

coolbutuseless/feck

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

feck

CRAN R-CMD-check

{feck} is an R package for generating forward error correction codes - think RAID5 or par2 but for raw vectors.

By pre-calculating a set of rescue blocks, if the data is later corrupted then these blocks can be used to repair the file.

The number of repair blocks generated is configurable depending upon user needs.

Installation

You can install the latest development version from GitHub with:

# install.package('remotes')
remotes::install_github('coolbutuseless/feck')

Example: Forward Error Correction of a raw vector

library(feck)

# Generate some data
set.seed(1)
dat0 <- dat <- as.raw(sample(0:255, 1e4, replace = TRUE))
length(dat)
#> [1] 10000
# Partitition the data into 10 chunks, and create 2 repair blocks.
# If errors occur in up to 2 of the chunks of data, then the data can 
# be repaired using these repair blocks
rblocks <- fec_prepare_raw(dat, k = 10, n = 2)
length(rblocks)
#> [1] 2112
# simulate damage to data
dat[1:100] <- as.raw(0)
identical(dat, dat0)
#> [1] FALSE
# repair the data using the repair blocks
dat_repaired <- fec_repair_raw(dat, rblocks)
identical(dat_repaired, dat0)
#> [1] TRUE

Example: Forward Error Correction of a file

library(feck)

# Same some data to a file
tmpfile <- tempfile()
saveRDS(mtcars, tmpfile)

# When reloaded it should be identical to what was saved
restore1 <- readRDS(tmpfile)
identical(mtcars, restore1)
#> [1] TRUE
# Create repair blocks. Consider the file split into 20 chunks,
# and create 5 repair blocks to repair errors in up to 5 chunks in the file
# The file is saved as the same as the original filename with a ".feck" suffix
fec_prepare_file(tmpfile, k = 20, n = 5)

# Corrupt the RDS file. Read it in, overwrite some bytes and save it back out
x <- readBin(tmpfile, raw(), n = file.size(tmpfile))
x[1:20] <- as.raw(0)
writeBin(x, tmpfile)

# Data is now unreadable!!
readRDS(tmpfile)
#> Error in readRDS(tmpfile): unknown input format
# Repair the file and save it with a ".repaired" suffix
fec_repair_file(tmpfile)

# Repaired data is now the same as the original
restore2 <- readRDS(paste0(tmpfile, ".repaired"))
identical(mtcars, restore2)
#> [1] TRUE

About

Forward Error Correction for R i.e. Erasure coding

Topics

Resources

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors