Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ jobs:

- name: Install dependencies
run: >
curl -sSL https://baltocdn.com/xp-framework/xp-runners/distribution/downloads/e/entrypoint/xp-run-9.1.0.sh > xp-run &&
curl -sSL https://github.com/xp-runners/reference/releases/download/v9.2.0/xp-run-9.2.0.sh > xp-run &&
composer install --prefer-dist &&
echo "vendor/autoload.php" > composer.pth

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"description" : "Compression I/O for the XP Framework",
"keywords": ["language", "module", "xp"],
"require" : {
"xp-framework/core": "^12.0 | ^11.0 | ^10.0",
"xp-framework/core": "^12.11 | ^11.11",
"php" : ">=7.4.0"
},
"require-dev" : {
Expand Down
4 changes: 2 additions & 2 deletions src/main/php/io/streams/compress/Brotli.class.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php namespace io\streams\compress;

use io\IOException;
use io\OperationFailed;
use io\streams\{InputStream, OutputStream, Compression};

class Brotli extends Algorithm {
Expand Down Expand Up @@ -31,7 +31,7 @@ public function compress(string $data, $options= null): string {
/** Decompresses bytes */
public function decompress(string $bytes): string {
if (false === ($data= brotli_uncompress($bytes))) {
$e= new IOException('Decompression failed');
$e= new OperationFailed('Decompression failed');
\xp::gc(__FILE__);
throw $e;
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/php/io/streams/compress/Bzip2.class.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php namespace io\streams\compress;

use io\IOException;
use io\OperationFailed;
use io\streams\{InputStream, OutputStream, Compression};

class Bzip2 extends Algorithm {
Expand Down Expand Up @@ -32,7 +32,7 @@ public function compress(string $data, $options= null): string {
public function decompress(string $bytes): string {
if (is_string($data= bzdecompress($bytes))) return $data;

$e= new IOException('Decompression failed ('.(false === $data ? 'general error' : 'error #'.$data).')');
$e= new OperationFailed('Decompression failed ('.(false === $data ? 'general error' : 'error #'.$data).')');
\xp::gc(__FILE__);
throw $e;
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/php/io/streams/compress/Bzip2InputStream.class.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php namespace io\streams\compress;

use io\IOException;
use io\OperationFailed;
use io\streams\{Streams, InputStream};

/**
Expand All @@ -16,14 +16,14 @@ class Bzip2InputStream implements InputStream {
* Constructor
*
* @param io.streams.InputStream $in
* @throws io.IOException
* @throws io.OperationFailed
*/
public function __construct(InputStream $in) {
$this->fd= Streams::readableFd($in);
if (!stream_filter_append($this->fd, 'bzip2.decompress', STREAM_FILTER_READ)) {
fclose($this->fd);
$this->fd= null;
throw new IOException('Could not append stream filter');
throw new OperationFailed('Could not append stream filter');
}
}

Expand All @@ -35,7 +35,7 @@ public function __construct(InputStream $in) {
*/
public function read($limit= 8192) {
if (false === ($bytes= fread($this->fd, $limit))) {
$e= new IOException('Reading compressed data failed');
$e= new OperationFailed('Reading compressed data failed');
\xp::gc(__FILE__);
throw $e;
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/php/io/streams/compress/Bzip2OutputStream.class.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php namespace io\streams\compress;

use io\IOException;
use io\OperationFailed;
use io\streams\{OutputStream, Streams};
use lang\IllegalArgumentException;

Expand All @@ -19,7 +19,7 @@ class Bzip2OutputStream implements OutputStream {
* @param io.streams.OutputStream $out
* @param int $level default 6
* @throws lang.IllegalArgumentException if the level is not between 0 and 9
* @throws io.IOException
* @throws io.OperationFailed
*/
public function __construct(OutputStream $out, $level= 6) {
if ($level < 0 || $level > 9) {
Expand All @@ -30,7 +30,7 @@ public function __construct(OutputStream $out, $level= 6) {
if (!stream_filter_append($this->fd, 'bzip2.compress', STREAM_FILTER_WRITE, ['blocks' => $level])) {
fclose($this->fd);
$this->fd= null;
throw new IOException('Could not append stream filter');
throw new OperationFailed('Could not append stream filter');
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php namespace io\streams\compress;

use io\IOException;
use io\OperationFailed;
use io\streams\{OutputStream, Streams};
use lang\IllegalArgumentException;

Expand Down Expand Up @@ -28,7 +28,7 @@ public function __construct(OutputStream $out, $level= 6) {
if (!stream_filter_append($this->out, 'zlib.deflate', STREAM_FILTER_WRITE, $level)) {
fclose($this->out);
$this->out= null;
throw new IOException('Could not append stream filter');
throw new OperationFailed('Could not append stream filter');
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/php/io/streams/compress/Gzip.class.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php namespace io\streams\compress;

use io\IOException;
use io\OperationFailed;
use io\streams\{InputStream, OutputStream, Compression};

class Gzip extends Algorithm {
Expand Down Expand Up @@ -31,7 +31,7 @@ public function compress(string $data, $options= null): string {
/** Decompresses bytes */
public function decompress(string $bytes): string {
if (false === ($data= gzuncompress($bytes))) {
$e= new IOException('Decompression failed');
$e= new OperationFailed('Decompression failed');
\xp::gc(__FILE__);
throw $e;
}
Expand Down
12 changes: 6 additions & 6 deletions src/main/php/io/streams/compress/GzipInputStream.class.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php namespace io\streams\compress;

use io\IOException;
use io\OperationFailed;
use io\streams\InputStream;

/**
Expand Down Expand Up @@ -61,7 +61,7 @@ public function stream_close() {
* Constructor
*
* @param io.streams.InputStream $in
* @throws io.IOException
* @throws io.OperationFailed
*/
public function __construct(InputStream $in) {
$header= '';
Expand All @@ -78,13 +78,13 @@ public function __construct(InputStream $in) {
// * OS (Operating system)
$this->header= unpack('a2id/Cmethod/Cflags/Vtime/Cextra/Cos', $header);
if ("\x1F\x8B" !== $this->header['id']) {
$e= new IOException('Invalid format, expected \037\213, have '.addcslashes($this->header['id'], "\0..\377"));
$e= new OperationFailed('Invalid format, expected \037\213, have '.addcslashes($this->header['id'], "\0..\377"));
\xp::gc(__FILE__);
throw $e;
}

if (8 !== $this->header['method']) {
throw new IOException('Unknown compression method #'.$this->header['method']);
throw new OperationFailed('Unknown compression method #'.$this->header['method']);
}

// Extract filename if present
Expand All @@ -103,7 +103,7 @@ public function __construct(InputStream $in) {
if (!stream_filter_append($this->fd, 'zlib.inflate', STREAM_FILTER_READ)) {
fclose($this->fd);
$this->fd= null;
throw new IOException('Could not append stream filter');
throw new OperationFailed('Could not append stream filter');
}
}

Expand All @@ -118,7 +118,7 @@ public function header() { return $this->header; }
*/
public function read($limit= 8192) {
if (false === ($bytes= fread($this->fd, $limit))) {
$e= new IOException('Reading compressed data failed');
$e= new OperationFailed('Reading compressed data failed');
\xp::gc(__FILE__);
throw $e;
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/php/io/streams/compress/GzipOutputStream.class.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php namespace io\streams\compress;

use io\IOException;
use io\OperationFailed;
use io\streams\{Streams, OutputStream};
use lang\IllegalArgumentException;

Expand All @@ -22,7 +22,7 @@ class GzipOutputStream implements OutputStream {
* @param io.streams.OutputStream $out
* @param int $level default 6
* @throws lang.IllegalArgumentException if the level is not between 0 and 9
* @throws io.IOException
* @throws io.OperationFailed
*/
public function __construct(OutputStream $out, $level= 6) {
if ($level < 0 || $level > 9) {
Expand All @@ -43,7 +43,7 @@ public function __construct(OutputStream $out, $level= 6) {
if (!($this->filter= stream_filter_append($this->fd, 'zlib.deflate', STREAM_FILTER_WRITE, $level))) {
fclose($this->fd);
$this->fd= null;
throw new IOException('Could not append stream filter');
throw new OperationFailed('Could not append stream filter');
}
$this->md= hash_init('crc32b');
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php namespace io\streams\compress;

use io\IOException;
use io\OperationFailed;
use io\streams\{Streams, InputStream};

/**
Expand All @@ -20,7 +20,7 @@ class InflatingInputStream implements InputStream {
public function __construct(InputStream $in) {
$this->in= Streams::readableFd($in);
if (!stream_filter_append($this->in, 'zlib.inflate', STREAM_FILTER_READ)) {
throw new IOException('Could not append stream filter');
throw new OperationFailed('Could not append stream filter');
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/main/php/io/streams/compress/Snappy.class.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php namespace io\streams\compress;

use io\IOException;
use io\OperationFailed;
use io\streams\{InputStream, OutputStream, Compression};

/** @see https://en.wikipedia.org/wiki/Snappy_(compression) */
Expand Down Expand Up @@ -171,13 +171,13 @@ public function decompress(string $bytes): string {
$l= $c >> 2;
if ($l >= 60) {
$n= $l - 59;
if ($pos + $n >= $limit) throw new IOException('Not enough input, expected '.$n);
if ($pos + $n >= $limit) throw new OperationFailed('Not enough input, expected '.$n);
$l= unpack('P', str_pad(substr($bytes, $pos, $n), 8, "\0"))[1];
$pos+= $n;
}

$l++;
if ($pos + $l > $limit) throw new IOException('Not enough input, expected '.$l);
if ($pos + $l > $limit) throw new OperationFailed('Not enough input, expected '.$l);

$out.= substr($bytes, $pos, $l);
$pos+= $l;
Expand All @@ -193,7 +193,7 @@ public function decompress(string $bytes): string {
break;

case 2:
if ($pos + 1 >= $limit) throw new IOException('Not enough input, expected 1');
if ($pos + 1 >= $limit) throw new OperationFailed('Not enough input, expected 1');

$l= 1 + ($c >> 2);
$offset= unpack('v', $bytes, $pos)[1];
Expand All @@ -204,7 +204,7 @@ public function decompress(string $bytes): string {
break;

case 3:
if ($pos + 3 >= $limit) throw new IOException('Not enough input, expected 3');
if ($pos + 3 >= $limit) throw new OperationFailed('Not enough input, expected 3');

$l= 1 + ($c >> 2);
$offset= unpack('V', $bytes, $pos)[1];
Expand All @@ -218,7 +218,7 @@ public function decompress(string $bytes): string {

// Verify uncompressed length
if ($length !== ($l= strlen($out))) {
throw new IOException('Expected length '.$length.', have '.$l);
throw new OperationFailed('Expected length '.$length.', have '.$l);
}

return $out;
Expand Down
6 changes: 3 additions & 3 deletions src/main/php/io/streams/compress/SnappyInputStream.class.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php namespace io\streams\compress;

use io\IOException;
use io\OperationFailed;
use io\streams\InputStream;

/** @test io.streams.compress.unittest.SnappyInputStreamTest */
Expand All @@ -14,14 +14,14 @@ class SnappyInputStream implements InputStream {
*
* @param int $n
* @return string
* @throws io.IOException
* @throws io.OperationFailed
*/
private function bytes($n) {
while (strlen($this->buffer) < $n) {
if ($this->in->available()) {
$this->buffer.= $this->in->read();
} else {
throw new IOException('Not enough input, expected '.$n);
throw new OperationFailed('Not enough input, expected '.$n);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/php/io/streams/compress/ZStandard.class.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php namespace io\streams\compress;

use io\IOException;
use io\OperationFailed;
use io\streams\{InputStream, OutputStream, Compression};

class ZStandard extends Algorithm {
Expand Down Expand Up @@ -31,7 +31,7 @@ public function compress(string $data, $options= null): string {
/** Decompresses bytes */
public function decompress(string $bytes): string {
if (false === ($data= zstd_uncompress($bytes))) {
$e= new IOException('Decompression failed');
$e= new OperationFailed('Decompression failed');
\xp::gc(__FILE__);
throw $e;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php namespace io\streams\compress;

use io\IOException;
use io\OperationFailed;
use io\streams\InputStream;

/**
Expand Down Expand Up @@ -32,7 +32,7 @@ public function __construct(InputStream $in) {
public function read($limit= 8192) {
$bytes= zstd_uncompress_add($this->handle, $this->in->read($limit));
if (false === $bytes) {
$e= new IOException('Failed to uncompress');
$e= new OperationFailed('Failed to uncompress');
\xp::gc(__FILE__);
throw $e;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php namespace io\streams\compress\unittest;

use io\IOException;
use io\OperationFailed;
use io\streams\{Compression, MemoryInputStream, MemoryOutputStream, Streams};
use lang\IllegalArgumentException;
use test\verify\Runtime;
Expand Down Expand Up @@ -138,7 +138,7 @@ public function streams_roundtrip($compressed) {
Assert::equals('Test', $result);
}

#[Test, Values(from: 'erroneous'), Expect(IOException::class)]
#[Test, Values(from: 'erroneous'), Expect(OperationFailed::class)]
public function decompress_erroneous($compressed, $bytes) {
$compressed->decompress($bytes);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php namespace io\streams\compress\unittest;

use io\IOException;
use io\OperationFailed;
use io\streams\{InputStream, MemoryInputStream};
use test\{Assert, Expect, Test, Values};
use util\Bytes;
Expand Down Expand Up @@ -60,7 +60,7 @@ public function at_level($level) {
Assert::equals('Hello', $chunk);
}

#[Test, Values(from: 'erroneous'), Expect(IOException::class)]
#[Test, Values(from: 'erroneous'), Expect(OperationFailed::class)]
public function reading_erroneous($data) {
$fixture= $this->fixture(new MemoryInputStream($data));
try {
Expand Down
Loading
Loading