Revision 396

Date:
2013/11/21 18:05:50
Author:
ahitrov
Revision Log:
Memory usage optimization during image anf binary store operations
Files:

Legend:

 
Added
 
Removed
 
Modified
  • koi8/core/lib/Contenido/File.pm

     
    225 225 syswrite $fh_tmp, $buffer, $size;
    226 226
    227 227 undef $fh_tmp;
    228 undef $buffer;
    228 229
    229 230 my $image_info = image_info($filename_tmp.'.'.$ext);
    230 231 if ( !(ref $image_info && $image_info->{width} && $image_info->{height}) || (ref $image_info && $image_info->{error}) ) {
     
    501 502 syswrite $fh_tmp, $buffer, $size;
    502 503
    503 504 undef $fh_tmp;
    505 undef $buffer;
    504 506
    505 507 my $BINARY;
    506 508 if ( store($filename.'.'.$ext, $filename_tmp.'.'.$ext) ) {
  • koi8/core/lib/Contenido/File/Scheme/FILE.pm

     
    5 5
    6 6 use Contenido::Globals;
    7 7 use Data::Dumper;
    8 use IO::File;
    8 9
    9 10 sub store {
    10 11 my $path = shift || return;
    11 12 my $fh = shift || return;
    12 13
    13 14 local $/ = undef;
    14
    15 my $content = <$fh>;
    16
    17 15 make_dir_recursive($path);
    18 16
    19 unless (open FILE, ">$path") {
    20 warn $!;
    21 return;
    17 my $size = (stat $fh)[7];
    18 if ( $size < 10485760 ) {
    19 my $content = <$fh>;
    20 unless (open FILE, "> $path") {
    21 warn $!;
    22 return;
    23 }
    24 print FILE $content;
    25 close FILE;
    26 } else {
    27 my ($offset, $limit, $buff) = (0, 524288, undef);
    28 my $dst = new IO::File;
    29 unless ($dst->open("> $path")) {
    30 warn $!;
    31 return;
    32 }
    33 while ( $size ) {
    34 my $len = $size > $limit ? $limit : $size;
    35 $fh->sysread( $buff, $len, $offset );
    36 $dst->syswrite( $buff, $len, $offset );
    37 $offset += $len;
    38 $size -= $len;
    39 undef $buff;
    40 }
    41 undef $dst;
    22 42 }
    23 43
    24 print FILE $content;
    25 close FILE;
    26
    27 44 return 1;
    28 45 }
    29 46