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):
%3 test_apm_tarballs apm_tarballs (test acs-tcl) util::file_content_check util::file_content_check test_apm_tarballs->util::file_content_check test_util__file_content_check util__file_content_check (test acs-tcl) test_util__file_content_check->util::file_content_check test_zip_and_unzip zip_and_unzip (test acs-tcl) test_zip_and_unzip->util::file_content_check util::zip util::zip (public) util::file_content_check->util::zip packages/file-storage/www/file-add.tcl packages/file-storage/ www/file-add.tcl packages/file-storage/www/file-add.tcl->util::file_content_check packages/file-storage/www/folder-zip-add.tcl packages/file-storage/ www/folder-zip-add.tcl packages/file-storage/www/folder-zip-add.tcl->util::file_content_check packages/xowiki/www/admin/import.tcl packages/xowiki/ www/admin/import.tcl packages/xowiki/www/admin/import.tcl->util::file_content_check search::convert::binary_to_text search::convert::binary_to_text (public) search::convert::binary_to_text->util::file_content_check

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

[ hide source ] | [ make this the default ]
Show another procedure: