/** * Open an input stream for reading and return URI * * @param io.streams.InputStream s * @return string */ public static function readableUri(InputStream $s) { self::$streams[$s->hashCode()] = $s; return 'iostrr://' . $s->hashCode(); }
/** * 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 ("‹" != $this->header['id']) { throw new IOException('Invalid format, expected \\037\\213, have ' . addcslashes($this->header['id'], "..ÿ")); } if (8 !== $this->header['method']) { throw new IOException('Unknown compression method #' . $this->header['method']); } if (8 === ($this->header['flags'] & 8)) { $this->header['filename'] = ''; while ("" !== ($b = $in->read(1))) { $this->header['filename'] .= $b; } } // Now, convert stream to file handle and append inflating filter $wri = 'zlib.bounded://' . $in->hashCode(); 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'); } }