19declare(strict_types=1);
45 int $next_version_number,
46 int $revision_owner_id,
47 string $revision_title,
51 $uri = $metadata[
'uri'];
56 $this->file_stream =
new ZIPStream(fopen($uri,
'rb'));
64 $this->suffix = pathinfo((
string) $this->file_name, PATHINFO_EXTENSION);
72 $this->mime_type =
'unknown';
73 if (function_exists(
'mime_content_type') && file_exists($this->path)) {
74 $this->mime_type = mime_content_type($this->path);
78 if (class_exists(
'finfo')) {
79 $finfo = finfo_open(FILEINFO_MIME_TYPE);
80 if ($this->file_stream->isSeekable()) {
82 $this->mime_type = finfo_buffer($finfo, $this->file_stream->read(255));
83 $this->file_stream->rewind();
88 if ($this->mime_type ===
'application/zip' && $this->suffix !==
'zip') {
91 if ($this->mime_type ===
'application/x-empty') {
101 $this->size = $this->file_stream->getSize();
102 }
catch (\Throwable) {
103 $mb_strlen_exists = function_exists(
'mb_strlen');
105 while ($content = $this->file_stream->read(1_048_576)) {
106 if ($mb_strlen_exists) {
107 $this->size += mb_strlen($content,
'8bit');
109 $this->size += strlen($content);
112 }
catch (\Throwable $exception) {
113 if ($this->file_stream->isSeekable()) {
114 $mb_strlen_exists = function_exists(
'mb_strlen');
116 while ($content = $this->file_stream->read(1_048_576)) {
117 if ($mb_strlen_exists) {
118 $this->size += mb_strlen($content,
'8bit');
120 $this->size += strlen($content);
123 $this->file_stream->rewind();
130 $filectime = file_exists($this->path) ? filectime($this->path) :
false;
131 $this->creation_date = $filectime ? (new \DateTimeImmutable())->setTimestamp(
133 ) : new \DateTimeImmutable();
142 $this->file_name = basename($this->path);
144 if ($this->file_name ===
'memory' || $this->file_name ===
'input' || $this->file_name ===
'temp') {
177 $suffix_with_dot =
'.' . $this->
getSuffix();
178 if (array_key_exists($suffix_with_dot, $mime_types_array)) {
179 return $mime_types_array[$suffix_with_dot];
181 return 'application/octet-stream';
initFileName(?string $file_name=null)
__construct(FileStream $file_stream, int $next_version_number, int $revision_owner_id, string $revision_title, ?string $file_name=null)
DateTimeImmutable $creation_date
The base interface for all filesystem streams.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc