Skip to content

Commit a26c4fc

Browse files
committed
Refactor file write APIs to use std::string_view and std::span<const char>
Updated test cases and C API implementations to use std::string_view for writeAll calls and std::span<const char> for byte data, improving type safety and consistency with modern C++ practices.
1 parent 7dde50c commit a26c4fc

File tree

4 files changed

+7
-7
lines changed

4 files changed

+7
-7
lines changed

Tests/VirtualFileSystem/VFSSimpleTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ int main() {
2626

2727
// Write
2828
std::cout << "Calling writeAll...\n";
29-
auto w = fh.writeAll("Hello from simple test!\n");
29+
auto w = fh.writeAll(std::string_view("Hello from simple test!\n"));
3030
std::cout << "Waiting for write...\n";
3131
w.wait();
3232
std::cout << "Write status: " << static_cast<int>(w.status()) << "\n";

Tests/VirtualFileSystem/VFSTests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ TEST(VFS, WriteReadDelete_InTempDir) {
2222
const std::string text = "Hello from VFSTests!\n";
2323

2424
// Write
25-
auto w = fh.writeAll(text);
25+
auto w = fh.writeAll(std::string_view(text));
2626
w.wait();
2727
ASSERT_EQ(w.status(), FileOpStatus::Complete) << "writeAll failed: " << w.errorInfo().message;
2828
EXPECT_EQ(w.bytesWritten(), static_cast<uint64_t>(text.size()));
@@ -47,7 +47,7 @@ TEST(VFS, ListTempDir_ShowsCreatedFile) {
4747
auto filePath = tmp.join("file.txt");
4848
auto fh = env.vfs().createFileHandle(filePath.string());
4949

50-
auto w = fh.writeAll("x");
50+
auto w = fh.writeAll(std::string_view("x"));
5151
w.wait();
5252
ASSERT_EQ(w.status(), FileOpStatus::Complete) << "writeAll failed: " << w.errorInfo().message;
5353

Tests/VirtualFileSystem/VFSTextFidelityTests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ TEST(VFSTextFidelity, WriteLine_BeyondEOF_ExtendsAndWrites) {
4646
auto fh = vfs.createFileHandle(path);
4747

4848
// Start with one line
49-
auto w0 = fh.writeAll("root\n");
49+
auto w0 = fh.writeAll(std::string_view("root\n"));
5050
w0.wait();
5151
ASSERT_EQ(w0.status(), FileOpStatus::Complete);
5252

src/entropy/entropy_file_handle_c.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ entropy_FileOperationHandle entropy_file_handle_write_all_bytes(
235235

236236
try {
237237
auto* cpp_handle = reinterpret_cast<FileHandle*>(handle);
238-
std::span<const std::byte> data(reinterpret_cast<const std::byte*>(bytes), length);
238+
std::span<const char> data(reinterpret_cast<const char*>(bytes), length);
239239
FileOperationHandle op = cpp_handle->writeAll(data);
240240
*status = ENTROPY_OK;
241241
return wrap_file_operation_handle(std::move(op));
@@ -260,7 +260,7 @@ entropy_FileOperationHandle entropy_file_handle_write_all_bytes_with_options(
260260

261261
try {
262262
auto* cpp_handle = reinterpret_cast<FileHandle*>(handle);
263-
std::span<const std::byte> data(reinterpret_cast<const std::byte*>(bytes), length);
263+
std::span<const char> data(reinterpret_cast<const char*>(bytes), length);
264264
WriteOptions wo = to_cpp_write_options(options);
265265
FileOperationHandle op = cpp_handle->writeAll(data, wo);
266266
*status = ENTROPY_OK;
@@ -286,7 +286,7 @@ entropy_FileOperationHandle entropy_file_handle_write_range(
286286

287287
try {
288288
auto* cpp_handle = reinterpret_cast<FileHandle*>(handle);
289-
std::span<const std::byte> data(reinterpret_cast<const std::byte*>(bytes), length);
289+
std::span<const char> data(reinterpret_cast<const char*>(bytes), length);
290290
FileOperationHandle op = cpp_handle->writeRange(offset, data);
291291
*status = ENTROPY_OK;
292292
return wrap_file_operation_handle(std::move(op));

0 commit comments

Comments
 (0)