Skip to content

Commit aa9387c

Browse files
trflynn89awesomekling
authored andcommitted
LibCore: Add a Resource method to create a file:// URL from a resource
1 parent e9aa72e commit aa9387c

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

Userland/Libraries/LibCore/Resource.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@ String Resource::filesystem_path() const
5858
return ResourceImplementation::the().filesystem_path(*this);
5959
}
6060

61+
String Resource::file_url() const
62+
{
63+
if (m_scheme == Scheme::File)
64+
return uri();
65+
66+
return MUST(String::formatted("file://{}", filesystem_path()));
67+
}
68+
6169
String Resource::filename() const
6270
{
6371
return MUST(String::from_utf8(LexicalPath(m_path.bytes_as_string_view()).basename()));

Userland/Libraries/LibCore/Resource.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class Resource : public RefCounted<Resource> {
3030
[[nodiscard]] String uri() const;
3131
[[nodiscard]] String filename() const;
3232
[[nodiscard]] String filesystem_path() const;
33+
[[nodiscard]] String file_url() const;
3334

3435
[[nodiscard]] ByteBuffer clone_data() const;
3536
[[nodiscard]] ByteBuffer release_data() &&;

0 commit comments

Comments
 (0)