Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/SmbAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,19 @@ public function copy(string $source, string $destination, Config $config): void
fclose($sourceStream);
}

/**
* Get the URL of a file.
*
* @param string $path
* @return string
*/
public function getUrl($path): string
{
$contents = $this->read($path);
$mimeType = $this->mimeTypeDetector->detectMimeType($path, $contents) ?? 'application/octet-stream';
return 'data:' . $mimeType . ';base64,' . base64_encode($contents);
}

/**
* Create the parent directories if they do not exist.
*
Expand Down
18 changes: 18 additions & 0 deletions tests/SmbAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,22 @@ public function moving_a_file(): void
$this->assertEquals('contents to be copied', $adapter->read('destination.txt'));
});
}

/**
* @test
*/
public function test_get_url_returns_valid_data_url(): void
{
$this->runScenario(function () {
$adapter = $this->adapter();
$filename = 'test.txt';
$content = 'Hello, world!';
$adapter->write($filename, $content, new Config());

$dataUrl = $adapter->getUrl($filename);

$this->assertStringStartsWith('data:text/plain;base64,', $dataUrl);
$this->assertStringContainsString(base64_encode($content), $dataUrl);
});
}
}