Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File type and magic 1

Status
Not open for further replies.

bdw238

MIS
Dec 15, 2005
52
GB
I using the compress::zlib library to gzip files in perl, which I have working. However, if use the `file` command on a perl procduced gzip file I get

/dag_t # file dag_t_1_1099_615050359.arc.gz
dag_t_1_1099_615050359.arc.gz: data or International Language text

istead of (using gzip command)

bearcat]: /oraachieve/dag_t # file dag_t_1_1099_615050359.arc.gz: gzip (.gz) compressed data


Brian
 
did you have a question Brian?

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 


Silly me,


How do I get the compress:zlib produced files to return

/oraachieve/dag_t # file dag_t_1_1099_615050359.arc.gz: gzip (.gz) compressed data


instead of

/dag_t # file dag_t_1_1099_615050359.arc.gz
dag_t_1_1099_615050359.arc.gz: data or International Language text

from the file command??

Brian
 
I don't know. But isn't the "file" command an operating system command? Maybe ask in the apporpriate operating system forum or wait here and see if someone knows.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 

Yes, the file command is used on Aix and linux. The reason I ask on perl form is to find out how to write the correct file signture to a perl produced gzip file.


Brian
 
Using the "gzstream" example from the Compress::Zlib documentation, I created a .gz file that produced the following output from "file":
Code:
$ file test.gz 
test.gz: gzip compressed data, from Unix

Using Perl v5.8.8 and Compress::Zlib v1.42 on Ubuntu Linux 7.04

What code are you using to create your zipped file?
 
The code is as follows:

sub gzip_file {

my $file = $_[0];
my $gzfile = $file.".gz";
my $buf;


open (FILE, $file);
binmode FILE;

my $gz = gzopen($gzfile, "wb");
if (! $gz) {
print "Unable to write $gzfile $!\n";
exit;
}
else {
while (my $by = sysread (FILE, $buf, 4096)) {
if (! $gz->gzwrite($buf)) {
print "Zlib error writing to $gzfile: $gz->gzerror\n";
exit;
}
}
$gz->gzclose();
close(FILE);
# Delete File
unlink($file);

return $gzfile;
}

Aix 5.2
Perl 5.8.8
Latest version of compress (2.004, I think).

Thanks

Brian

 
I get the same result as I did when I ran the other example, so I don't think I can help any more I'm afraid.
 
According to the doc on CPAN, the module you are using writes the shortest possible header by default. For full control over what gets written to the header, you need to use IO::Compress::Gzip.

Maybe 'file' interprets the header differently on different OSs?



Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
Thanks Stevexff,

I discovered the IP:Compress::Gzip function last night. I have test this morning and seems to done the trick.

Thanks for the help


Brian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top