Skip to content

michal-josef-spacek/Dicom-File-Detect

Repository files navigation

NAME
    Dicom::File::Detect - Detect DICOM file through magic string.

SYNOPSIS
     use Dicom::File::Detect qw(dicom_detect_file);

     my $dcm_flag = dicom_detect_file($file);

DESCRIPTION
    This Perl module detect DICOM file through magic string. DICOM (Digital
    Imaging and Communications in Medicine) is a standard for handling,
    storing, printing, and transmitting information in medical imaging. See
    DICOM on Wikipedia <https://en.wikipedia.org/wiki/DICOM>.

SUBROUTINES
  "dicom_detect_file"
     my $dcm_flag = dicom_detect_file($file);

    Detect DICOM file.

    Returns 1/0.

ERRORS
     dicom_detect_file():
             Cannot close file '%s'.
             Cannot open file '%s'.

EXAMPLE1
     use strict;
     use warnings;

     use Dicom::File::Detect qw(dicom_detect_file);
     use File::Temp qw(tempfile);
     use IO::Barf qw(barf);
     use MIME::Base64;

     # Data in base64.
     my $data = <<'END';
     AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
     AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
     AAAAAAAAAAAAAAAAAABESUNNCg==
     END

     # Temp file.
     my (undef, $temp_file) = tempfile();

     # Save data to file.
     barf($temp_file, decode_base64($data));

     # Check file.
     my $dcm_flag = dicom_detect_file($temp_file);

     # Print out.
     if ($dcm_flag) {
             print "File '$temp_file' is DICOM file.\n";
     } else {
             print "File '$temp_file' isn't DICOM file.\n";
     }

     # Output like:
     # File '%s' is DICOM file.

EXAMPLE2
     use strict;
     use warnings;

     use Dicom::File::Detect qw(dicom_detect_file);

     # Arguments.
     if (@ARGV < 1) {
             print STDERR "Usage: $0 file\n";
             exit 1;
     }
     my $file = $ARGV[0];

     # Check file.
     my $dcm_flag = dicom_detect_file($file);

     # Print out.
     if ($dcm_flag) {
             print "File '$file' is DICOM file.\n";
     } else {
             print "File '$file' isn't DICOM file.\n";
     }

     # Output:
     # Usage: dicom-detect-file file

DEPENDENCIES
    Error::Pure, Exporter, Readonly.

SEE ALSO
    File::Find::Rule::Dicom
        Common rules for searching for DICOM things.

    Task::Dicom
        Install the Dicom modules.

REPOSITORY
    <https://github.com/michal-josef-spacek/Dicom-File-Detect>

AUTHOR
    Michal Josef Špaček <mailto:skim@cpan.org>

    <http://skim.cz>

LICENSE AND COPYRIGHT
    © 2014-2021 Michal Josef Špaček

    BSD 2-Clause License

VERSION
    0.06

About

Detect DICOM file through magic string.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages