forked from xp-framework/core
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileInputStream.class.php
More file actions
executable file
·80 lines (69 loc) · 1.66 KB
/
Copy pathFileInputStream.class.php
File metadata and controls
executable file
·80 lines (69 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php namespace io\streams;
use io\File;
use lang\Value;
use util\Comparison;
/**
* InputStream that reads from a file
*
* @test io.unittest.FileInputStreamTest
*/
class FileInputStream implements InputStream, Seekable, Value {
use Comparison;
protected $file;
/**
* Constructor
*
* @param io.File|string $file Either a file instance or a file name
*/
public function __construct($file) {
$this->file= $file instanceof File ? $file : new File($file);
$this->file->isOpen() || $this->file->open(File::READ);
}
/**
* Read a string
*
* @param int limit default 8192
* @return string
*/
public function read($limit= 8192) {
return (string)$this->file->read($limit);
}
/**
* Returns the number of bytes that can be read from this stream
* without blocking.
*
* @return int
*/
public function available() {
return $this->file->size() - $this->file->tell();
}
/**
* Close this buffer
*
*/
public function close() {
$this->file->isOpen() && $this->file->close();
}
/**
* Creates a string representation of this file
*
* @return string
*/
public function toString() {
return nameof($this).'<'.$this->file->toString().'>';
}
/**
* Seek to a given offset
*
* @param int offset
* @param int whence default SEEK_SET (one of SEEK_[SET|CUR|END])
* @throws io.IOException in case of error
*/
public function seek($offset, $whence= SEEK_SET) {
$this->file->seek($offset, $whence);
}
/** @return int */
public function tell() { return $this->file->tell(); }
/** @return int */
public function size() { return $this->file->size(); }
}