Skip to content

Commit 2e7533b

Browse files
committed
always store directories with file size 0. fixes #15
1 parent c075304 commit 2e7533b

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

src/FileInfo.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,11 @@ public static function fromPath($path, $as = '')
7474
}
7575

7676
/**
77-
* @return int
77+
* @return int the filesize. always 0 for directories
7878
*/
7979
public function getSize()
8080
{
81+
if($this->isdir) return 0;
8182
return $this->size;
8283
}
8384

tests/FileInfo.test.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,17 @@ public function testMatch()
8383
$this->assertFalse($fileinfo->match('/bang/', '/foo/'));
8484
$this->assertTrue($fileinfo->match('/bang/', '/bark/'));
8585
}
86+
87+
public function testFromPath()
88+
{
89+
$fileinfo = FileInfo::fromPath(__DIR__ . '/zip/block.txt', 'test.txt');
90+
$this->assertEquals('test.txt', $fileinfo->getPath());
91+
$this->assertFalse($fileinfo->getIsdir());
92+
$this->assertSame(512, $fileinfo->getSize());
93+
94+
$fileinfo = FileInfo::fromPath(__DIR__ . '/zip', 'zip');
95+
$this->assertEquals('zip', $fileinfo->getPath());
96+
$this->assertTrue($fileinfo->getIsdir());
97+
$this->assertSame(0, $fileinfo->getSize());
98+
}
8699
}

0 commit comments

Comments
 (0)