Skip to content

Commit

Permalink
make mogupload work with piped data.
Browse files Browse the repository at this point in the history
  • Loading branch information
dormando committed Jan 5, 2011
1 parent 2d4afa2 commit 8cb5913
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions mogupload
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,24 @@ my $mogc = $util->client;
my $filename = $c->{file};

my $fh;
my $size;
my $size = 0;
if ($filename eq '-') {
# Can't upload files without a known filesize?
die "STDIN mode not yet supported";
$fh = *STDIN;
} else {
$size = -s $filename;
die "Could not stat " . $filename unless defined $size;
open($fh, "< $filename") or die "Could not open " . $filename;
}

my $mf = $mogc->new_file($c->{key}, $c->{class}, $size);
my $mf = $mogc->new_file($c->{key}, $c->{class}, undef);
if ($mogc->errcode) {
die "Error opening MogileFS file: " . $mogc->errstr;
}

my $buf;
while (my $read = read($fh, $buf, 32768)) {
while (my $read = read($fh, $buf, 1024 * 1024)) {
die "error reading file" unless defined $read;
last if $read == 0;
print $mf $buf;
$mf->print($buf);
}

unless ($mf->close) {
Expand Down

0 comments on commit 8cb5913

Please sign in to comment.