Subject: | Support read/writes via file handle [patch] |
This patch makes it so that the file names given to the Audio::Wav::Read
and Audio::Wav::Write constructors may also be a GLOB (such as \*STDIN)
and will be handled as such.
Certain caveats exist, however, in using file handles, though. For
instance, the size isn't known, and it is entirely possible to
accidentally read past the end of the file. As long as
Subject: | Audio-Wav-0.12_file_handle_support.patch |
diff -ru Audio-Wav-0.12.orig/Wav/Read.pm Audio-Wav-0.12/Wav/Read.pm
--- Audio-Wav-0.12.orig/Wav/Read.pm 2010-05-23 11:37:07.000000000 -0500
+++ Audio-Wav-0.12/Wav/Read.pm 2011-10-15 22:20:42.000000000 -0500
@@ -47,7 +47,10 @@
my $tools = shift;
$file =~ s#//#/#g;
my $size = -s $file;
- my $handle = new FileHandle "<$file";
+ my $handle =
+ (ref $file eq 'GLOB') ?
+ $file :
+ new FileHandle "<$file";
my $self = {
'real_size' => $size,
diff -ru Audio-Wav-0.12.orig/Wav/Write.pm Audio-Wav-0.12/Wav/Write.pm
--- Audio-Wav-0.12.orig/Wav/Write.pm 2010-05-23 11:37:07.000000000 -0500
+++ Audio-Wav-0.12/Wav/Write.pm 2011-10-15 22:20:32.000000000 -0500
@@ -76,7 +76,10 @@
my $details = shift;
my $tools = shift;
- my $handle = new FileHandle ">$out_file";
+ my $handle =
+ (ref $out_file eq 'GLOB') ?
+ $out_file :
+ new FileHandle ">$out_file";
my $use_cache = 1;
if ( ref $details eq 'HASH' && exists $details -> {'no_cache'} ) {