Skip to content

Commit d85aadd

Browse files
committed
Add meta information
1 parent da6fa86 commit d85aadd

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

src/main/php/io/Blob.class.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,16 @@
99
class Blob implements IteratorAggregate, Value {
1010
private $parts;
1111
private $iterator= null;
12+
public $meta= [];
1213

1314
/**
1415
* Creates a new blob from parts
1516
*
1617
* @param iterable|string|util.Bytes|io.streams.InputStream $parts
18+
* @param [:var] $meta
1719
* @throws lang.IllegalArgumentException
1820
*/
19-
public function __construct($parts= []) {
21+
public function __construct($parts= [], array $meta= []) {
2022
if ($parts instanceof InputStream) {
2123
$this->iterator= function() {
2224
static $started= false;
@@ -44,6 +46,7 @@ public function __construct($parts= []) {
4446
}
4547

4648
$this->parts= $parts;
49+
$this->meta= $meta;
4750
}
4851

4952
/** @return iterable */

src/test/php/io/unittest/BlobTest.class.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,17 @@ public function not_from_null() {
3232
new Blob(null);
3333
}
3434

35+
#[Test]
36+
public function meta_empty_by_default() {
37+
Assert::equals([], (new Blob('Test'))->meta);
38+
}
39+
40+
#[Test]
41+
public function meta() {
42+
$meta= ['type' => 'text/plain'];
43+
Assert::equals($meta, (new Blob('Test', $meta))->meta);
44+
}
45+
3546
#[Test, Values(from: 'cases')]
3647
public function iteration($fixture, $expected) {
3748
Assert::equals($expected, iterator_to_array($fixture));

0 commit comments

Comments
 (0)