checkSha256: Validate files by SHA256 checksum hashing

View source: R/getData.R

checkSha256R Documentation

Validate files by SHA256 checksum hashing

Description

Validates files by calculating their SHA256 checksums and comparing them to the expected hash. Returns a named boolean vector indicating matching or mismatching files, by path. error can be set to return FALSE or NA for problem files instead of throwing an error. File names can be any mix of absolute and relative paths, where relative is to the current working directory.

Usage

checkSha256(checksums = NULL, files = NULL, error = NA, ext = ".sha256")

Arguments

checksums

A vector or list of expected checksums. If named, they will be treated as a dictionary of hash values. If unnamed, file names must be provided in parallel in files. This is optional when note files identified by ext are being used to store checksum values. It is an error if only some checksums have names.

files

The files to check as a string vector. If checksums are not provided, note files containing the checksum will looked for based on ext. If checksums are unnamed, files must match in order and length. When checksums are named, files is optional and will default to the checksum names.

error

Boolean value. NA or FALSE specifies the result to return when files are missing (either files to be validated or expected note files). Setting this TRUE causes an error to be thrown when a file is not found, halting checking.

ext

If only files are specified and checksums are not, checksums are expected to be provided in "note" files stored on the file system in parallel to the files being validated. For every file to check, the name of the matching "note" file is obtained by suffixing this extension to the name of the file it matches. The note file should contain the checksum of the matching file as a string. The hash string should be the only thing in the file. It doesn't matter if the checksum string ends with an EOL or not. This generally should start with a "." and by default will be .sha256.

Details

The expected checksums hash strings for files can be provided as a list or vector and can be named. The files specified via files will be validated using these checksums. If named, all checksums must be named for the path to the file they validate. They are treated like a "dictionary" from which the expected checksum of a file can be looked up, by path. If unnamed, then checksums must be in the same order and have the same length as the provided files vector.

If checksums are not specified, then for each file in files, a "note" file containing the string checksum as its only content (EOL optional) will be looked for. They are expected to be named the same as the files, but with the addition of the extension ext (by default .sha256). It is an error if an expected .sha256 note file is not found, but this behavior can be configured by setting error.

Value

A boolean vector indicating if files match their provided SHA256 checksum hashes.


jefferys/JefferysRUtils documentation built on Jan. 12, 2024, 9:18 p.m.