Skip to content

Commit b612c2c

Browse files
committed
fix(linux): ImageSource.toBase64String without a temp file
Encodes the PNG in memory instead of leaving ns-image-<ms>.png files (which collided within the same millisecond) in the cache folder.
1 parent 7906dfb commit b612c2c

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

‎packages/core/image-source/index.linux.ts‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -236,16 +236,16 @@ export class ImageSource implements ImageSourceDefinition {
236236
}
237237

238238
public toBase64String(format: 'png' | 'jpeg' | 'jpg', quality?: number): string {
239-
const file = fsPath.join(knownFolders.temp().path, `ns-image-${Date.now()}.png`);
240-
if (!this.saveToFile(file, format, quality)) {
239+
if (!this._linux) {
240+
return null;
241+
}
242+
// encoded in memory, no temp file
243+
const size = new interop.Reference(interop.types.uint64, 0);
244+
const data = g_bytes_unref_to_data(gdk_texture_save_to_png_bytes(this._linux), size);
245+
if (!data) {
241246
return null;
242247
}
243-
const bytes = new Uint8Array(
244-
knownFolders
245-
.temp()
246-
.getFile(file.substring(file.lastIndexOf('/') + 1))
247-
.readSync(),
248-
);
248+
const bytes = new Uint8Array(interop.bufferFromData(data as any, Number(size.value), g_free));
249249
let binary = '';
250250
for (let i = 0; i < bytes.length; i++) binary += String.fromCharCode(bytes[i]);
251251
return btoa(binary);

0 commit comments

Comments
 (0)