Skip to content

Commit eab912f

Browse files
committed
PHPLIB-250: GridFS stat should report chunk size in blksize field
1 parent ddd2c3e commit eab912f

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/GridFS/StreamWrapper.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,12 @@ public function stream_stat()
150150
: 0100222; // S_IFREG & S_IWUSR & S_IWGRP & S_IWOTH
151151
$stat[7] = $stat['size'] = $this->stream->getSize();
152152

153+
$file = $this->stream->getFile();
154+
155+
if (isset($file->chunkSize) && is_integer($file->chunkSize)) {
156+
$stat[11] = $stat['blksize'] = $file->chunkSize;
157+
}
158+
153159
return $stat;
154160
}
155161

tests/GridFS/StreamWrapperFunctionalTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ public function testReadableStreamStat()
5858
$this->assertSame(0100444, $stat['mode']);
5959
$this->assertSame(10, $stat[7]);
6060
$this->assertSame(10, $stat['size']);
61+
$this->assertSame(4, $stat[11]);
62+
$this->assertSame(4, $stat['blksize']);
6163
}
6264

6365
public function testReadableStreamWrite()
@@ -97,13 +99,15 @@ public function testWritableStreamRead()
9799

98100
public function testWritableStreamStat()
99101
{
100-
$stream = $this->bucket->openUploadStream('filename');
102+
$stream = $this->bucket->openUploadStream('filename', ['chunkSizeBytes' => 1024]);
101103

102104
$stat = fstat($stream);
103105
$this->assertSame(0100222, $stat[2]);
104106
$this->assertSame(0100222, $stat['mode']);
105107
$this->assertSame(0, $stat[7]);
106108
$this->assertSame(0, $stat['size']);
109+
$this->assertSame(1024, $stat[11]);
110+
$this->assertSame(1024, $stat['blksize']);
107111

108112
$this->assertSame(6, fwrite($stream, 'foobar'));
109113

0 commit comments

Comments
 (0)