util::file_content_check (public)
util::file_content_check -type type -filename filename
Defined in packages/acs-tcl/tcl/utilities-procs.tcl
Check whether the provided file is of the requested type. This function is more robust and portable than relying on external programs and their output, but it does not work on all possible file types. It checks a few common cases that could lead to problems otherwise, like when uploading archives.
- Switches:
- -type (required)
- -filename (required)
- Returns:
- Boolean value (0 or 1)
- Partial Call Graph (max 5 caller/called nodes):
- Testcases:
- apm_tarballs, zip_and_unzip, util__file_content_check
Source code: set known_signatures { zip 504b0304 gzip 1f8b pdf 255044462d xz fd377a585a00 bz2 425A68 export 23206578706f7274696e6720 } if {[dict exists $known_signatures $type]} { set hex_signature [dict get $known_signatures $type] set len [expr {[string length $hex_signature] / 2}] set F [open $filename rb] set signature [read $F $len] close $F return [expr {[binary encode hex $signature] eq $hex_signature}] } else { error "util::file_content_check called with unsupported file type '$type'" }XQL Not present: PostgreSQL, Oracle Generic XQL file: packages/acs-tcl/tcl/utilities-procs.xql