Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1441
Línea 93... Línea 93...
93
    {
93
    {
94
        $forecastSize = $this->forecastSize();
94
        $forecastSize = $this->forecastSize();
Línea 95... Línea 95...
95
 
95
 
96
        if ($this->enableZeroHeader) {
96
        if ($this->enableZeroHeader) {
97
            // No calculation required
97
            // No calculation required
98
        } elseif ($this->isSimulation() && $forecastSize) {
98
        } elseif ($this->isSimulation() && $forecastSize !== null) {
99
            $this->uncompressedSize = $forecastSize;
99
            $this->uncompressedSize = $forecastSize;
100
            $this->compressedSize = $forecastSize;
100
            $this->compressedSize = $forecastSize;
101
        } else {
101
        } else {
102
            $this->readStream(send: false);
102
            $this->readStream(send: false);
Línea 105... Línea 105...
105
            }
105
            }
106
        }
106
        }
Línea 107... Línea 107...
107
 
107
 
Línea 108... Línea 108...
108
        $this->addFileHeader();
108
        $this->addFileHeader();
Línea 109... Línea 109...
109
 
109
 
110
        $detectedSize = $forecastSize ?? $this->compressedSize;
110
        $detectedSize = $forecastSize ?? ($this->compressedSize > 0 ? $this->compressedSize : null);
111
 
111
 
112
        if (
112
        if (
-
 
113
            $this->isSimulation() &&
-
 
114
            $detectedSize !== null
113
            $this->isSimulation() &&
115
        ) {
114
            $detectedSize > 0
116
            $this->uncompressedSize = $detectedSize;
115
        ) {
117
            $this->compressedSize = $detectedSize;
116
            ($this->recordSentBytes)($detectedSize);
118
            ($this->recordSentBytes)($detectedSize);
Línea 156... Línea 158...
156
    private function forecastSize(): ?int
158
    private function forecastSize(): ?int
157
    {
159
    {
158
        if ($this->compressionMethod !== CompressionMethod::STORE) {
160
        if ($this->compressionMethod !== CompressionMethod::STORE) {
159
            return null;
161
            return null;
160
        }
162
        }
161
        if ($this->exactSize) {
163
        if ($this->exactSize !== null) {
162
            return $this->exactSize;
164
            return $this->exactSize;
163
        }
165
        }
164
        $fstat = fstat($this->unpackStream());
166
        $fstat = fstat($this->unpackStream());
165
        if (!$fstat || !array_key_exists('size', $fstat) || $fstat['size'] < 1) {
167
        if (!$fstat || !array_key_exists('size', $fstat) || $fstat['size'] < 1) {
166
            return null;
168
            return null;
Línea 182... Línea 184...
182
 
184
 
Línea 183... Línea 185...
183
        $footer = $this->buildZip64ExtraBlock($forceEnableZip64);
185
        $footer = $this->buildZip64ExtraBlock($forceEnableZip64);
Línea 184... Línea 186...
184
 
186
 
185
        $zip64Enabled = $footer !== '';
187
        $zip64Enabled = $footer !== '';
186
 
188
 
Línea 187... Línea 189...
187
        if($zip64Enabled) {
189
        if ($zip64Enabled) {
188
            $this->version = Version::ZIP64;
190
            $this->version = Version::ZIP64;
Línea 329... Línea 331...
329
                self::CHUNKED_READ_BLOCK_SIZE
331
                self::CHUNKED_READ_BLOCK_SIZE
330
            );
332
            );
Línea 331... Línea 333...
331
 
333
 
Línea -... Línea 334...
-
 
334
            $data = fread($this->unpackStream(), $readLength);
-
 
335
 
-
 
336
            if ($data === false) {
-
 
337
                throw new ResourceActionException('fread', $this->unpackStream());
332
            $data = fread($this->unpackStream(), $readLength);
338
            }
Línea 333... Línea 339...
333
 
339
 
Línea 334... Línea 340...
334
            hash_update($hash, $data);
340
            hash_update($hash, $data);
335
 
341
 
336
            $this->uncompressedSize += strlen($data);
342
            $this->uncompressedSize += strlen($data);
337
 
343
 
338
            if ($deflate) {
344
            if ($deflate) {
339
                $data =  deflate_add(
345
                $data =  deflate_add(
-
 
346
                    $deflate,
-
 
347
                    $data,
-
 
348
                    feof($this->unpackStream()) ? ZLIB_FINISH : ZLIB_NO_FLUSH
-
 
349
                );
340
                    $deflate,
350
 
Línea 341... Línea 351...
341
                    $data,
351
                if ($data === false) {
Línea 342... Línea 352...
342
                    feof($this->unpackStream()) ? ZLIB_FINISH : ZLIB_NO_FLUSH
352
                    throw new RuntimeException('deflate_add failed');
343
                );
353
                }
344
            }
354
            }
345
 
355
 
Línea 346... Línea 356...
346
            $this->compressedSize += strlen($data);
356
            $this->compressedSize += strlen($data);
347
 
357
 
348
            if ($send) {
358
            if ($send) {
Línea 349... Línea 359...
349
                ($this->send)($data);
359
                ($this->send)($data);
350
            }
360
            }
Línea 351... Línea 361...
351
        }
361
        }
352
 
362
 
353
        if ($this->exactSize && $this->uncompressedSize !== $this->exactSize) {
363
        if ($this->exactSize !== null && $this->uncompressedSize !== $this->exactSize) {
354
            throw new FileSizeIncorrectException(expectedSize: $this->exactSize, actualSize: $this->uncompressedSize);
364
            throw new FileSizeIncorrectException(expectedSize: $this->exactSize, actualSize: $this->uncompressedSize);
355
        }
365
        }
356
 
366
 
357
        $this->crc = hexdec(hash_final($hash));
367
        $this->crc = hexdec(hash_final($hash));
358
    }
368
    }
Línea 388... Línea 398...
388
    {
398
    {
389
        $footer = $this->buildZip64ExtraBlock();
399
        $footer = $this->buildZip64ExtraBlock();
Línea 390... Línea 400...
390
 
400
 
391
        return CentralDirectoryFileHeader::generate(
401
        return CentralDirectoryFileHeader::generate(
392
            versionMadeBy: ZipStream::ZIP_VERSION_MADE_BY,
402
            versionMadeBy: ZipStream::ZIP_VERSION_MADE_BY,
393
            versionNeededToExtract:$this->version->value,
403
            versionNeededToExtract: $this->version->value,
394
            generalPurposeBitFlag: $this->generalPurposeBitFlag,
404
            generalPurposeBitFlag: $this->generalPurposeBitFlag,
395
            compressionMethod: $this->compressionMethod,
405
            compressionMethod: $this->compressionMethod,
396
            lastModificationDateTime: $this->lastModificationDateTime,
406
            lastModificationDateTime: $this->lastModificationDateTime,
397
            crc32: $this->crc,
407
            crc32: $this->crc,