71//PassRefPtr<SharedBuffer> SharedBuffer::createWithContentsOfFile(const String&) { notImplemented(); return 0; }
72
73PassRefPtr<SharedBuffer> SharedBuffer::createWithContentsOfFile(const String& filePath)
74{
75 if (filePath.isEmpty())
76 return 0;
77
78 gchar* filename = g_filename_from_utf8(filePath.utf8().data(), -1, 0, 0, 0);
79 if (!filename)
80 return 0;
81
82 gchar* contents;
83 gsize size;
84 GError* error = 0;
85 if (!g_file_get_contents(filename, &contents, &size, &error)) {
86 LOG_ERROR("Failed to fully read contents of file %s - %s", filePath.utf8().data(), error->message);
87 g_error_free(error);
88 g_free(filename);
89 return 0;
90 }
91
92 RefPtr<SharedBuffer> result = SharedBuffer::create(contents, size);
93 g_free(filename);
94 g_free(contents);
95
96 return result.release();
97}
98