Debian Codegraph @

lib/3rdParty/composer/aws/aws-crt-php/src/AWS/CRT/IO/InputStream.php

raw symbols SCIP
1 <?php
2 /**
3 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
4 * SPDX-License-Identifier: Apache-2.0.
5 */
6 namespace AWS\CRT\IO;
7
8 use AWS\CRT\NativeResource as NativeResource;
9
10 final class InputStream extends NativeResource {
11 private $stream = null;
12
13 const SEEK_BEGIN = 0;
14 const SEEK_END = 2;
15
16 public function __construct($stream) {
17 parent::__construct();
18 $this->stream = $stream;
19 $options = self::$crt->input_stream_options_new();
20 // The stream implementation in native just converts the PHP stream into
21 // a native php_stream* and executes operations entirely in native
22 self::$crt->input_stream_options_set_user_data($options, $stream);
23 $this->acquire(self::$crt->input_stream_new($options));
24 self::$crt->input_stream_options_release($options);
25 }
26
27 public function __destruct() {
28 $this->release();
29 parent::__destruct();
30 }
31
32 public function eof() {
33 return self::$crt->input_stream_eof($this->native);
34 }
35
36 public function length() {
37 return self::$crt->input_stream_get_length($this->native);
38 }
39
40 public function read($length = 0) {
41 if ($length == 0) {
42 $length = $this->length();
43 }
44 return self::$crt->input_stream_read($this->native, $length);
45 }
46
47 public function seek($offset, $basis) {
48 return self::$crt->input_stream_seek($this->native, $offset, $basis);
49 }
50 }