mirror of
https://github.com/Intervention/image.git
synced 2025-08-23 05:52:47 +02:00
Fix bug in File::class
The missing call to rewind() resulted in the file being saved with empty content if File::save() was called twice in succession.
This commit is contained in:
@@ -70,7 +70,7 @@ class File implements FileInterface, Stringable
|
|||||||
}
|
}
|
||||||
|
|
||||||
// write data
|
// write data
|
||||||
$saved = @file_put_contents($filepath, $this->pointer);
|
$saved = @file_put_contents($filepath, $this->toFilePointer());
|
||||||
if ($saved === false) {
|
if ($saved === false) {
|
||||||
throw new NotWritableException(
|
throw new NotWritableException(
|
||||||
sprintf("Can't write image data to path (%s).", $filepath)
|
sprintf("Can't write image data to path (%s).", $filepath)
|
||||||
@@ -85,7 +85,7 @@ class File implements FileInterface, Stringable
|
|||||||
*/
|
*/
|
||||||
public function toString(): string
|
public function toString(): string
|
||||||
{
|
{
|
||||||
return stream_get_contents($this->pointer, offset: 0);
|
return stream_get_contents($this->toFilePointer(), offset: 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -107,7 +107,7 @@ class File implements FileInterface, Stringable
|
|||||||
*/
|
*/
|
||||||
public function size(): int
|
public function size(): int
|
||||||
{
|
{
|
||||||
$info = fstat($this->pointer);
|
$info = fstat($this->toFilePointer());
|
||||||
|
|
||||||
return intval($info['size']);
|
return intval($info['size']);
|
||||||
}
|
}
|
||||||
|
@@ -41,11 +41,21 @@ final class FileTest extends BaseTestCase
|
|||||||
|
|
||||||
public function testSave(): void
|
public function testSave(): void
|
||||||
{
|
{
|
||||||
$filename = __DIR__ . '/file_' . strval(hrtime(true)) . '.test';
|
|
||||||
$file = new File('foo');
|
$file = new File('foo');
|
||||||
$file->save($filename);
|
$filenames = [
|
||||||
$this->assertTrue(file_exists($filename));
|
__DIR__ . '/01_file_' . strval(hrtime(true)) . '.test',
|
||||||
unlink($filename);
|
__DIR__ . '/02_file_' . strval(hrtime(true)) . '.test',
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach ($filenames as $name) {
|
||||||
|
$file->save($name);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($filenames as $name) {
|
||||||
|
$this->assertFileExists($name);
|
||||||
|
$this->assertEquals('foo', file_get_contents($name));
|
||||||
|
unlink($name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testToString(): void
|
public function testToString(): void
|
||||||
|
Reference in New Issue
Block a user