Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MogileFS::Client newfile seems to miss FILENO? #22

Open
GoogleCodeExporter opened this issue Mar 16, 2015 · 0 comments
Open

MogileFS::Client newfile seems to miss FILENO? #22

GoogleCodeExporter opened this issue Mar 16, 2015 · 0 comments

Comments

@GoogleCodeExporter
Copy link
Contributor

From: J. Shirley

I am trying to write directly to the filehandle while working with
Imager, and I noticed an odd issue when I try to do so.  If Imager
writes to the disk, then sends the file (or, to a scalar and sends
that via store_file or I print directly) it works just fine.  Only
when I try to pass the filehandle in:

I get this error:
Can't locate object method "FILENO" via package
"MogileFS::NewHTTPFile" at /Library/Perl/5.8.8/darwin-thread-
multi-2level/Imager.pm line 1250, <Sock_tengu:6001> line 1.

The code in question there is:
    my $fd = fileno($input->{fh});
    unless (defined $fd) {
      $self->_set_error("Handle in fh option not opened");
      return;
    }
    # flush it
    my $oldfh = select($input->{fh});
    # flush anything that's buffered, and make sure anything else is
flushed
    $| = 1;
    select($oldfh);
    return io_new_fd($fd);

So, the reasons are fairly sound (it writes to the fd, rather than a
perl filehandle) but... why?  What is the advantage of this over other
things, and is it possible/desired to patch NewHTTPFile.pm to support
FILENO?

And here's my test:
use Imager;
use MogileFS::Client;

my $store = MogileFS::Client->new(
    domain => 'example.com',
    hosts  => [ 'test:6001' ]
);

my $fh    = $store->new_file("test_image", "user_media");
die "Can't allocate fh\n" unless $fh;

my $image = Imager->new;
$image->read( file => 'root/static/images/nav-back.png' )
    or die "Can't read image: " . $image->errstr;
my $type = $image->tags( name => 'i_format' );
warn "Writing out $type to $fh\n";
my $scale = $image->scale(xpixels => 1280, ypixels => 1024, type =>
'min');
$scale->write( fh => $fh, type => $type );

unless ( $fh->close ) {
    die "Error writing file: " .  $store->errcode . ": " . $store-
>errstr;
}

Original issue reported on code.google.com by [email protected] on 2 Oct 2010 at 10:40

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant