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.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)
Run the code above in your browser using DataLab