Skip to content

Commit fa7c168

Browse files
committed
Optimized the etag algorithm and content-type
1 parent 3e40975 commit fa7c168

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/Stream/SwooleFileStream.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
namespace Hyperf\HttpMessage\Stream;
1414

15+
use Hyperf\HttpServer\Exception\Http\FileException;
1516
use InvalidArgumentException;
1617
use Psr\Http\Message\StreamInterface;
1718

@@ -30,15 +31,18 @@ class SwooleFileStream implements StreamInterface, FileInterface
3031
/**
3132
* SwooleFileStream constructor.
3233
*
33-
* @param string $file
34+
* @param string|\SplFileInfo $file
3435
*/
35-
public function __construct(string $file)
36+
public function __construct($file)
3637
{
37-
if (! file_exists($file)) {
38-
throw new InvalidArgumentException('Not a file');
38+
if (! $file instanceof \SplFileInfo) {
39+
$file = new \SplFileInfo($file);
3940
}
40-
$this->contents = $file;
41-
$this->size = filesize($file);
41+
if (! $file->isReadable()) {
42+
throw new FileException('File must be readable.');
43+
}
44+
$this->contents = $file->getPathname();
45+
$this->size = $file->getSize();
4246
}
4347

4448
/**

0 commit comments

Comments
 (0)