diff --git a/src/main/php/io/streams/Bz2CompressingOutputStream.class.php b/src/main/php/io/streams/Bz2CompressingOutputStream.class.php deleted file mode 100755 index a1d7e5e3b..000000000 --- a/src/main/php/io/streams/Bz2CompressingOutputStream.class.php +++ /dev/null @@ -1,79 +0,0 @@ - 9) { - throw new IllegalArgumentException('Level '.$level.' out of range [0..9]'); - } - - $this->out= Streams::writeableFd($out); - if (!stream_filter_append($this->out, 'bzip2.compress', STREAM_FILTER_WRITE, ['blocks' => $level])) { - fclose($this->out); - $this->out= null; - throw new IOException('Could not append stream filter'); - } - } - - /** - * Write a string - * - * @param var arg - */ - public function write($arg) { - fwrite($this->out, $arg); - } - - /** - * Flush this buffer - * - */ - public function flush() { - fflush($this->out); - } - - /** - * Close this buffer. Flushes this buffer and then calls the close() - * method on the underlying OuputStream. - * - */ - public function close() { - if (!$this->out) return; - fclose($this->out); - $this->out= null; - } - - /** - * Destructor. Ensures output stream is closed. - * - */ - public function __destruct() { - $this->close(); - } - - - /** @return string */ - public function toString() { - return nameof($this).'(->'.$this->in.')'; - } -} diff --git a/src/main/php/io/streams/Bz2DecompressingInputStream.class.php b/src/main/php/io/streams/Bz2DecompressingInputStream.class.php deleted file mode 100755 index 91f2ef715..000000000 --- a/src/main/php/io/streams/Bz2DecompressingInputStream.class.php +++ /dev/null @@ -1,71 +0,0 @@ -in= Streams::readableFd($in); - if (!stream_filter_append($this->in, 'bzip2.decompress', STREAM_FILTER_READ)) { - throw new IOException('Could not append stream filter'); - } - } - - /** - * Read a string - * - * @param int limit default 8192 - * @return string - */ - public function read($limit= 8192) { - return fread($this->in, $limit); - } - - /** - * Returns the number of bytes that can be read from this stream - * without blocking. - * - */ - public function available() { - return feof($this->in) ? 0 : 1; - } - - /** - * Close this buffer. - * - */ - public function close() { - if (!$this->in) return; - fclose($this->in); - $this->in= null; - } - - /** - * Destructor. Ensures output stream is closed. - * - */ - public function __destruct() { - $this->close(); - } - - /** @return string */ - public function toString() { - return nameof($this).'(->'.$this->in.')'; - } -} \ No newline at end of file diff --git a/src/main/php/io/streams/DeflatingOutputStream.class.php b/src/main/php/io/streams/DeflatingOutputStream.class.php deleted file mode 100755 index d05d5339d..000000000 --- a/src/main/php/io/streams/DeflatingOutputStream.class.php +++ /dev/null @@ -1,77 +0,0 @@ - 9) { - throw new \lang\IllegalArgumentException('Level '.$level.' out of range [0..9]'); - } - $this->out= Streams::writeableFd($out); - if (!stream_filter_append($this->out, 'zlib.deflate', STREAM_FILTER_WRITE, $level)) { - fclose($this->out); - $this->out= null; - throw new \io\IOException('Could not append stream filter'); - } - } - - /** - * Write a string - * - * @param var arg - */ - public function write($arg) { - fwrite($this->out, $arg); - } - - /** - * Flush this buffer - * - */ - public function flush() { - fflush($this->out); - } - - /** - * Close this buffer. Flushes this buffer and then calls the close() - * method on the underlying OuputStream. - * - */ - public function close() { - if (!$this->out) return; - fclose($this->out); - $this->out= null; - } - - /** - * Destructor. Ensures output stream is closed. - * - */ - public function __destruct() { - $this->close(); - } - - - /** @return string */ - public function toString() { - return nameof($this).'(->'.$this->out.')'; - } -} diff --git a/src/main/php/io/streams/GzCompressingOutputStream.class.php b/src/main/php/io/streams/GzCompressingOutputStream.class.php deleted file mode 100755 index 1f98b937f..000000000 --- a/src/main/php/io/streams/GzCompressingOutputStream.class.php +++ /dev/null @@ -1,109 +0,0 @@ - 9) { - throw new \lang\IllegalArgumentException('Level '.$level.' out of range [0..9]'); - } - - // Write GZIP format header: - // * ID1, ID2 (Identification, \x1F, \x8B) - // * CM (Compression Method, 8 = deflate) - // * FLG (Flags, use 0) - // * MTIME (Modification time, Un*x timestamp) - // * XFL (Extra flags, 2 = compressor used maximum compression) - // * OS (Operating system, 255 = unknown) - $out->write(pack('CCCCVCC', 0x1F, 0x8B, 8, 0, time(), 2, 255)); - - // Now, convert stream to file handle and append deflating filter - $this->out= Streams::writeableFd($out); - if (!($this->filter= stream_filter_append($this->out, 'zlib.deflate', STREAM_FILTER_WRITE, $level))) { - fclose($this->out); - $this->out= null; - throw new \io\IOException('Could not append stream filter'); - } - $this->md= hash_init('crc32b'); - } - - /** - * Write a string - * - * @param var arg - */ - public function write($arg) { - fwrite($this->out, $arg); - $this->length+= strlen($arg); - hash_update($this->md, $arg); - } - - /** - * Flush this buffer - * - */ - public function flush() { - fflush($this->out); - } - - /** - * Close this buffer. Flushes this buffer and then calls the close() - * method on the underlying OuputStream. - * - */ - public function close() { - if (!$this->out) return; - - // Remove deflating filter so we can continue writing "raw" - stream_filter_remove($this->filter); - - $final= hash_final($this->md, true); - - // Write GZIP footer: - // * CRC32 (CRC-32 checksum) - // * ISIZE (Input size) - fwrite($this->out, pack('aaaaV', $final[3], $final[2], $final[1], $final[0], $this->length)); - fclose($this->out); - $this->out= null; - $this->md= null; - } - - /** - * Destructor. Ensures output stream is closed. - * - */ - public function __destruct() { - if (!$this->out) return; - fclose($this->out); - $this->out= null; - } - - /** @return string */ - public function toString() { - return nameof($this).'(->'.$this->out.')'; - } -} diff --git a/src/main/php/io/streams/GzDecompressingInputStream.class.php b/src/main/php/io/streams/GzDecompressingInputStream.class.php deleted file mode 100755 index 141036577..000000000 --- a/src/main/php/io/streams/GzDecompressingInputStream.class.php +++ /dev/null @@ -1,144 +0,0 @@ -st= GzDecompressingInputStream::$wrapped[$path]; - $this->id= $path; - return true; - } - - public function stream_read($count) { - - // Ensure we have at least 9 bytes - $l= strlen($this->buffer); - while ($l < 9 && $this->st->available() > 0) { - $chunk= $this->st->read($count); - $l+= strlen($chunk); - $this->buffer.= $chunk; - } - - // Now return the everything except the last 8 bytes - $read= substr($this->buffer, 0, -8); - $this->buffer= substr($this->buffer, -8); - return $read; - } - - public function stream_eof() { - return 0 === $this->st->available(); - } - - public function stream_flush() { - return true; - } - - public function stream_close() { - $this->st->close(); - unset(GzDecompressingInputStream::$wrapped[$this->id]); - } - })); - } - - /** - * Constructor - * - * @param io.streams.InputStream $in - * @throws io.IOException - */ - public function __construct(InputStream $in) { - - // Read GZIP format header - // * ID1, ID2 (Identification, \x1F, \x8B) - // * CM (Compression Method, 8 = deflate) - // * FLG (Flags) - // * MTIME (Modification time, Un*x timestamp) - // * XFL (Extra flags) - // * OS (Operating system) - $this->header= unpack('a2id/Cmethod/Cflags/Vtime/Cextra/Cos', $in->read(10)); - if ("\x1F\x8B" != $this->header['id']) { - throw new IOException('Invalid format, expected \037\213, have '.addcslashes($this->header['id'], "\0..\377")); - } - if (8 !== $this->header['method']) { - throw new IOException('Unknown compression method #'.$this->header['method']); - } - if (8 === ($this->header['flags'] & 8)) { - $this->header['filename']= ''; - while ("\x00" !== ($b= $in->read(1))) { - $this->header['filename'].= $b; - } - } - - // Now, convert stream to file handle and append inflating filter - $wri= 'zlib.bounded://'.spl_object_hash($in); - self::$wrapped[$wri]= $in; - $this->in= fopen($wri, 'r'); - if (!stream_filter_append($this->in, 'zlib.inflate', STREAM_FILTER_READ)) { - throw new IOException('Could not append stream filter'); - } - } - - /** @return [:var] */ - public function header() { return $this->header; } - - /** - * Read a string - * - * @param int limit default 8192 - * @return string - */ - public function read($limit= 8192) { - return fread($this->in, $limit); - } - - /** - * Returns the number of bytes that can be read from this stream - * without blocking. - * - */ - public function available() { - return feof($this->in) ? 0 : 1; - } - - /** - * Close this buffer. - * - */ - public function close() { - if (!$this->in) return; - fclose($this->in); - $this->in= null; - } - - /** - * Destructor. Ensures output stream is closed. - */ - public function __destruct() { - $this->close(); - } - - /** @return string */ - public function toString() { - return nameof($this).'(->'.$this->in.')'; - } -} diff --git a/src/main/php/io/streams/InflatingInputStream.class.php b/src/main/php/io/streams/InflatingInputStream.class.php deleted file mode 100755 index 16dcf2a75..000000000 --- a/src/main/php/io/streams/InflatingInputStream.class.php +++ /dev/null @@ -1,70 +0,0 @@ -in= Streams::readableFd($in); - if (!stream_filter_append($this->in, 'zlib.inflate', STREAM_FILTER_READ)) { - throw new \io\IOException('Could not append stream filter'); - } - } - - /** - * Read a string - * - * @param int limit default 8192 - * @return string - */ - public function read($limit= 8192) { - return fread($this->in, $limit); - } - - /** - * Returns the number of bytes that can be read from this stream - * without blocking. - * - */ - public function available() { - return feof($this->in) ? 0 : 1; - } - - /** - * Close this buffer. - * - */ - public function close() { - if (!$this->in) return; - fclose($this->in); - $this->in= null; - } - - /** - * Destructor. Ensures output stream is closed. - * - */ - public function __destruct() { - $this->close(); - } - - /** @return string */ - public function toString() { - return nameof($this).'(->'.$this->in.')'; - } -} diff --git a/src/test/php/io/unittest/AbstractCompressingOutputStreamTest.class.php b/src/test/php/io/unittest/AbstractCompressingOutputStreamTest.class.php deleted file mode 100755 index 19e7de947..000000000 --- a/src/test/php/io/unittest/AbstractCompressingOutputStreamTest.class.php +++ /dev/null @@ -1,101 +0,0 @@ -newStream($out, 6); - $compressor->write('Hello'); - $compressor->close(); - $this->assertCompressedDataEquals($this->compress('Hello', 6), $out->bytes()); - } - - #[Test] - public function multipeWrites() { - $out= new MemoryOutputStream(); - $compressor= $this->newStream($out, 6); - $compressor->write('Hello'); - $compressor->write(' '); - $compressor->write('World'); - $compressor->close(); - $this->assertCompressedDataEquals($this->compress('Hello World', 6), $out->bytes()); - } - - #[Test] - public function highestLevel() { - $out= new MemoryOutputStream(); - $compressor= $this->newStream($out, 9); - $compressor->write('Hello'); - $compressor->close(); - $this->assertCompressedDataEquals($this->compress('Hello', 9), $out->bytes()); - } - - #[Test] - public function lowestLevel() { - $out= new MemoryOutputStream(); - $compressor= $this->newStream($out, 1); - $compressor->write('Hello'); - $compressor->close(); - $this->assertCompressedDataEquals($this->compress('Hello', 1), $out->bytes()); - } - - #[Test, Expect(IllegalArgumentException::class)] - public function levelTooHigh() { - $this->newStream(new MemoryOutputStream() , 10); - } - - #[Test, Expect(IllegalArgumentException::class)] - public function levelTooLow() { - $this->newStream(new MemoryOutputStream(), -1); - } - - #[Test] - public function closingRightAfterCreation() { - $compressor= $this->newStream(new MemoryOutputStream(), 1); - $compressor->close(); - } - - #[Test] - public function closingTwice() { - $compressor= $this->newStream(new MemoryOutputStream(), 1); - $compressor->close(); - $compressor->close(); - } -} \ No newline at end of file diff --git a/src/test/php/io/unittest/AbstractDecompressingInputStreamTest.class.php b/src/test/php/io/unittest/AbstractDecompressingInputStreamTest.class.php deleted file mode 100755 index c5bff128c..000000000 --- a/src/test/php/io/unittest/AbstractDecompressingInputStreamTest.class.php +++ /dev/null @@ -1,78 +0,0 @@ -compress('Hello', 6)); - $decompressor= $this->newStream($in); - $chunk= $decompressor->read(); - $decompressor->close(); - Assert::equals('Hello', $chunk); - } - - #[Test] - public function multiple_reads() { - $in= new MemoryInputStream($this->compress('Hello World', 6)); - $decompressor= $this->newStream($in); - $chunk1= $decompressor->read(5); - $chunk2= $decompressor->read(1); - $chunk3= $decompressor->read(5); - $decompressor->close(); - Assert::equals('Hello', $chunk1); - Assert::equals(' ', $chunk2); - Assert::equals('World', $chunk3); - } - - #[Test] - public function highest_level() { - $in= new MemoryInputStream($this->compress('Hello', 9)); - $decompressor= $this->newStream($in); - $chunk= $decompressor->read(); - $decompressor->close(); - Assert::equals('Hello', $chunk); - } - - #[Test] - public function lowest_level() { - $in= new MemoryInputStream($this->compress('Hello', 1)); - $decompressor= $this->newStream($in); - $chunk= $decompressor->read(); - $decompressor->close(); - Assert::equals('Hello', $chunk); - } - - #[Test] - public function closing_right_after_creation() { - $decompressor= $this->newStream(new MemoryInputStream($this->compress('Hello', 1))); - $decompressor->close(); - } - - #[Test] - public function closing_twice_has_no_effect() { - $decompressor= $this->newStream(new MemoryInputStream($this->compress('Hello', 1))); - $decompressor->close(); - $decompressor->close(); - } -} \ No newline at end of file diff --git a/src/test/php/io/unittest/Bz2CompressingOutputStreamTest.class.php b/src/test/php/io/unittest/Bz2CompressingOutputStreamTest.class.php deleted file mode 100755 index 50702470d..000000000 --- a/src/test/php/io/unittest/Bz2CompressingOutputStreamTest.class.php +++ /dev/null @@ -1,30 +0,0 @@ -newStream(new MemoryInputStream($data)); - $chunk= $decompressor->read(); - $decompressor->close(); - Assert::equals('Hello', $chunk); - } - - #[Test, Values(from: 'dataWithFileName')] - public function header_with_original_filename($data) { - $decompressor= $this->newStream(new MemoryInputStream($data)); - $decompressor->close(); - Assert::equals('test.txt', $decompressor->header()['filename']); - } -} \ No newline at end of file diff --git a/src/test/php/io/unittest/InflatingInputStreamTest.class.php b/src/test/php/io/unittest/InflatingInputStreamTest.class.php deleted file mode 100755 index 12f2cd6a8..000000000 --- a/src/test/php/io/unittest/InflatingInputStreamTest.class.php +++ /dev/null @@ -1,33 +0,0 @@ -