[Vienna-pm] Datei binär kopieren (unter Windows)
Gerfried Fuchs
alfie at ist.org
Wed Jun 4 04:56:33 CDT 2003
* Peter Seitz <seitz at bzs.tu-graz.ac.at> [2003-06-02 22:45]:
> Was mache ich falsch? Ist es sinnvoll die Dateigröße festzustellen und
> dann in einem Schubs die Datei zu lesen? Das könnte aber IMHO bei
> sehr großen Dateien das Programm auch zum Absturz bringen, oder?
Nein. Ich würde Dir folgenden Snippet empfehlen:
#v+
open (IN, $input) || die "$0: can't read from »$input«: $!\n";
open (OUT, $output) || die "$0: can't write to »$output«: $!\n";
my $len = (stat($input))[11];
while (sysread IN, my $data, $len) { syswrite OUT, $data };
close OUT;
close IN;
#v-
Der Knackpunkt ist hier »(stat($input))[11]«, wieso Du so arbeiten
willst, siehst Du in »perldoc -f stat«:
11 blksize preferred block size for file system I/O
Ich hätte noch kein Dateisystem gesehen, dass eine so riesige Blocksize
bevorzugt, dass das Programm abstürzt ;)
Gegebenenfalls binmode verwenden, aber ich bin mir grad nicht sicher,
ob das bei sysread/syswrite überhaupt notwendig ist. Ich verwende obiges
Snippet, um Bilder-Dateien auf auf einer Webseite auszugeben, die nicht
im Document-Root liegen (wegen Zugriffskontrolle), hab diesbezüglich
keine Probleme bemerkt, und verwende hier binmode gar nicht.
HTH & HAND,
Alfie
--
It's simply unbelievable how much energy and creativity people have
invested into creating contradictory, bogus and stupid licenses...
--- Sven Rudolph about licences in debian/non-free.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://mail.pm.org/pipermail/vienna-pm/attachments/20030604/05e809a5/attachment.bin
More information about the Vienna-pm
mailing list