Index: trunk/DataStore/Build.PL
===================================================================
--- trunk/DataStore/Build.PL	(revision 17551)
+++ trunk/DataStore/Build.PL	(revision 17552)
@@ -12,4 +12,5 @@
         'Data::Validate::URI'   => '0.01',
         'Digest::MD5::File'     => '0.03',
+        'IPC::Cmd'              => '0.36',
         'File::Basename'        => 0,
         'File::Temp'            => '0.16',
Index: trunk/DataStore/Changes
===================================================================
--- trunk/DataStore/Changes	(revision 17551)
+++ trunk/DataStore/Changes	(revision 17552)
@@ -2,4 +2,5 @@
 
 0.07
+    - add support for checksumming compressed fits files
     - Change DateStore::File to handle passing args to LWP::UserAgent
     - add dsget --timeout option
Index: trunk/DataStore/lib/DataStore/File.pm
===================================================================
--- trunk/DataStore/lib/DataStore/File.pm	(revision 17551)
+++ trunk/DataStore/lib/DataStore/File.pm	(revision 17552)
@@ -1,5 +1,5 @@
 # Copyright (C) 2006  Joshua Hoblitt
 #
-# $Id: File.pm,v 1.17 2008-05-06 02:35:22 jhoblitt Exp $
+# $Id: File.pm,v 1.18 2008-05-07 03:05:03 jhoblitt Exp $
 
 package DataStore::File;
@@ -17,10 +17,13 @@
 use DataStore::Utils qw( $STD_FIELD $BYTE_FIELD $MD5_FIELD %KNOWN_FILE_TYPES );
 use Digest::MD5::File qw( file_md5_hex );
+use File::Basename qw( basename );
+use File::Temp ();
 use File::stat;
-use Params::Validate qw( validate SCALAR ARRAYREF );
+use IPC::Cmd 0.36 qw( can_run run );
+use Params::Validate qw( validate SCALAR ARRAYREF UNDEF );
 
 use vars qw( @BASE_FIELDS );
 
-@BASE_FIELDS = qw( fileid bytes md5sum type extra );
+@BASE_FIELDS = qw( fileid bytes md5sum type extra compressed );
 
 __PACKAGE__->mk_accessors(@BASE_FIELDS);
@@ -158,4 +161,8 @@
                 optional    => 1,
             },
+            compressed => {
+                type        => SCALAR | UNDEF,
+                optional    => 1,
+            },
         },
     );
@@ -228,4 +235,6 @@
         },
     );
+
+    my $verbose = 0;
 
     # make request
@@ -241,7 +250,37 @@
 
     if ($response->is_success) {
+        my $funpack;
+        if ($self->compressed) {
+            $funpack = can_run('funpack')
+                or warn "can't find funpack -- unable to compute checksum";
+        }
+
+        my $chk_file = $filename;
+        # so that the tmp file stays in scope until we're done processing
+        my $tmp;
+        if ($funpack) {
+            $tmp = File::Temp->new(
+                DIR         => '/tmp',
+                TEMPLATE    => basename($filename) . '.XXXXXXXX',
+                SUFFIX      => '.tmp',
+                UNLINK      => 1,
+            );
+
+            my $unpacked_path = $tmp->filename;
+
+            my $command = "$funpack -S -C $filename > $unpacked_path";
+            my ($success, $status, $full_buf, $stdout_buf, $stderr_buf)
+                = run(command => $command, verbose => $verbose);
+
+            unless ($success) {
+                die "funpack returned exit status $status\n";
+            }
+
+            $chk_file = $unpacked_path;
+        }
+
         # check size
         if (defined $self->bytes) {
-            my $size = stat($filename)->size;
+            my $size = stat($chk_file)->size;
             if (! ($self->bytes == $size)) {
                 unlink $filename;
@@ -251,9 +290,14 @@
                 # set the filename to undef to indicate an error
                 $filename = undef;
+            } else {
+                carp "uri: ", $self->uri,
+                     " - expected size: ", $self->bytes,
+                     " got: ", $size
+                if $verbose;
             }
         }
 
         if (defined $filename and defined $self->md5sum) {
-            my $md5 = file_md5_hex($filename);
+            my $md5 = file_md5_hex($chk_file);
             if (! ($self->md5sum eq $md5)) {
                 unlink $filename;
@@ -263,4 +307,9 @@
                 # set the filename to undef to indicate an error
                 $filename = undef;
+            } else {
+                carp "uri: ", $self->uri,
+                     " - expected md5: ", $self->md5sum,
+                     " got: ", $md5
+                if $verbose;
             }
         }
Index: trunk/DataStore/scripts/dsget
===================================================================
--- trunk/DataStore/scripts/dsget	(revision 17551)
+++ trunk/DataStore/scripts/dsget	(revision 17552)
@@ -3,5 +3,5 @@
 # Copyright (C) 2006-2008  Joshua Hoblitt
 #
-# $Id: dsget,v 1.22 2008-05-07 01:54:20 jhoblitt Exp $
+# $Id: dsget,v 1.23 2008-05-07 03:05:03 jhoblitt Exp $
 
 use strict;
@@ -76,4 +76,5 @@
 $p{bytes} = $bytes if defined $bytes; 
 $p{md5sum} = $md5 if defined $md5;
+$p{compressed} = 1 if defined $compress;
 
 my $tmp;
