NAME
CAD::AutoCAD::Detect - Detect AutoCAD files through magic string.
SYNOPSIS
my
$dwg_magic
= detect_dwg_file(
$file
);
DESCRIPTION
This Perl module detect AutoCAD files through magic string.
List of supported files: dwg
SUBROUTINES
detect_dwg_file
my
$dwg_magic
= detect_dwg_file(
$file
);
Detect DWG file.
Returns magic string or undef.
ERRORS
detect_dwg_file():
Cannot
close
file
'%s'
.
Cannot
open
file
'%s'
.
EXAMPLE1
use
strict;
use
warnings;
use
MIME::Base64;
# Data in base64.
my
$data
=
<<'END';
QUMxMDAyAAAAAAAAAAAAAAAK
END
# Temp file.
my
(
undef
,
$temp_file
) = tempfile();
# Save data to file.
barf(
$temp_file
, decode_base64(
$data
));
# Check file.
my
$dwg_magic
= detect_dwg_file(
$temp_file
);
# Print out.
if
(
$dwg_magic
) {
"File '$temp_file' is DWG file.\n"
;
}
else
{
"File '$temp_file' isn't DWG file.\n"
;
}
# Output like:
# File '%s' is DWG file.
EXAMPLE2
use
strict;
use
warnings;
# Arguments.
if
(
@ARGV
< 1) {
STDERR
"Usage: $0 file\n"
;
exit
1;
}
my
$file
=
$ARGV
[0];
# Check DWG file.
my
$dwg_magic
= detect_dwg_file(
$file
);
# Print out.
if
(
$dwg_magic
) {
"File '$file' is DWG file.\n"
;
}
else
{
"File '$file' isn't DWG file.\n"
;
}
# Output:
# Usage: detect-dwg-file file
DEPENDENCIES
CAD::AutoCAD::Version, Error::Pure, Exporter, List::Util, Readonly.
REPOSITORY
https://github.com/michal-josef-spacek/CAD-AutoCAD-Detect
AUTHOR
Michal Josef Špaček mailto:skim@cpan.org
LICENSE AND COPYRIGHT
© 2020-2024 Michal Josef Špaček
BSD 2-Clause License
VERSION
0.04