Description Usage Arguments Details Value Author(s) References Examples
Create hash function digests for a GDS node.
1 2 | digest.gdsn(node, algo=c("md5", "sha1", "sha256", "sha384", "sha512"),
action=c("none", "Robject", "add", "add.Robj", "clear", "verify", "return"))
|
node |
an object of class |
algo |
the algorithm to be used; currently available choices are "md5" (by default), "sha1", "sha256", "sha384", "sha512" |
action |
"none": nothing (by default); "Robject": convert to R object,
i.e., raw, integer, double or character before applying hash digests;
"add": add a barcode attribute; "add.Robj": add a barcode attribute
generated from R object; "clear": remove all hash barcodes;
"verify": verify data integrity if there is any hash code in the
attributes, and stop if any fails; "return": compare the existing hash
code in the attributes, and return |
The R package digest
should be installed to perform hash function
digests.
A character or NA_character_
when the hash algorithm is not
available.
Xiuwen Zheng
http://github.com/zhengxwen/gdsfmt
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 | library(digest)
library(tools)
# cteate a GDS file
f <- createfn.gds("test.gds")
val <- as.raw(rep(1:128, 1024))
n1 <- add.gdsn(f, "raw1", val)
n2 <- add.gdsn(f, "int1", as.integer(val))
n3 <- add.gdsn(f, "int2", as.integer(val), compress="ZIP", closezip=TRUE)
digest.gdsn(n1)
digest.gdsn(n1, action="Robject")
digest.gdsn(n1, action="add")
digest.gdsn(n1, action="add.Robj")
writeBin(read.gdsn(n1, .useraw=TRUE), con="test1.bin")
write.gdsn(n1, 0, start=1027, count=1)
digest.gdsn(n1, action="add")
digest.gdsn(n1, action="add.Robj")
digest.gdsn(n1, "sha1", action="add")
digest.gdsn(n1, "sha256", action="add")
# digest.gdsn(n1, "sha384", action="add") ## digest_0.6.11 does not work
digest.gdsn(n1, "sha512", action="add")
writeBin(read.gdsn(n1, .useraw=TRUE), con="test2.bin")
print(n1, attribute=TRUE)
digest.gdsn(n1, action="verify")
digest.gdsn(n1, action="clear")
print(n1, attribute=TRUE)
digest.gdsn(n2)
digest.gdsn(n2, action="Robject")
# using R object
digest.gdsn(n2) == digest.gdsn(n3) # FALSE
digest.gdsn(n2, action="Robject") == digest.gdsn(n3, action="Robject") # TRUE
# close the GDS file
closefn.gds(f)
# check with other program
md5sum(c("test1.bin", "test2.bin"))
# delete the temporary file
unlink(c("test.gds", "test1.bin", "test2.bin"), force=TRUE)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.