1. Check a tar file
- Posted by jmduro Oct 24, 2017
- 1079 views
Here is a small function to check if a file is a tar archive
include get.e function isTar(sequence filename) sequence signature integer f_in, c, n puts(1, "Filename: "&filename&"\n") f_in = open(filename, "rb") if f_in = -1 then return 0 end if puts(1, "File found\n") n = 0 signature = "" while n < 261 do c = getc(f_in) if c = -1 then exit end if n += 1 if n > 256 then signature &= c puts(1, "Signature: "&signature&"\n") end if if n = 261 then if equal(signature, "ustar") then close(f_in) return 1 end if end if end while close(f_in) return 0 end function
Jean-Marc