diff options
author | fiaxh <git@lightrise.org> | 2019-02-13 21:50:15 +0100 |
---|---|---|
committer | fiaxh <git@lightrise.org> | 2019-02-14 00:04:01 +0100 |
commit | 736522737f4dae39af126353abfe26903b2c82ea (patch) | |
tree | c0e607550476b779e263fd772894e5816ee645cd /libdino/src | |
parent | d668e0158df40e1bb1ea00ab72fac9d0e95e8bd9 (diff) | |
download | dino-736522737f4dae39af126353abfe26903b2c82ea.tar.gz dino-736522737f4dae39af126353abfe26903b2c82ea.zip |
Make file read/write async
Diffstat (limited to 'libdino/src')
-rw-r--r-- | libdino/src/entity/file_transfer.vala | 1 | ||||
-rw-r--r-- | libdino/src/service/avatar_storage.vala | 4 | ||||
-rw-r--r-- | libdino/src/service/file_manager.vala | 12 |
3 files changed, 8 insertions, 9 deletions
diff --git a/libdino/src/entity/file_transfer.vala b/libdino/src/entity/file_transfer.vala index 2c45aa08..6b1492d6 100644 --- a/libdino/src/entity/file_transfer.vala +++ b/libdino/src/entity/file_transfer.vala @@ -44,7 +44,6 @@ public class FileTransfer : Object { input_stream_ = value; } } - public OutputStream output_stream { get; set; } public string file_name { get; set; } private string? server_file_name_ = null; diff --git a/libdino/src/service/avatar_storage.vala b/libdino/src/service/avatar_storage.vala index 46b43d99..f40414d1 100644 --- a/libdino/src/service/avatar_storage.vala +++ b/libdino/src/service/avatar_storage.vala @@ -17,7 +17,7 @@ public class AvatarStorage : Xep.PixbufStorage, Object { try { if (file.query_exists()) file.delete(); //TODO y? DataOutputStream fos = new DataOutputStream(file.create(FileCreateFlags.REPLACE_DESTINATION)); - fos.write(data); + fos.write_async.begin(data); } catch (Error e) { // Ignore: we failed in storing, so we refuse to display later... } @@ -36,4 +36,4 @@ public class AvatarStorage : Xep.PixbufStorage, Object { } } } -}
\ No newline at end of file +} diff --git a/libdino/src/service/file_manager.vala b/libdino/src/service/file_manager.vala index 241bcebf..4763d721 100644 --- a/libdino/src/service/file_manager.vala +++ b/libdino/src/service/file_manager.vala @@ -34,7 +34,7 @@ public class FileManager : StreamInteractionModule, Object { DirUtils.create_with_parents(get_storage_dir(), 0700); } - public void send_file(string uri, Conversation conversation) { + public async void send_file(string uri, Conversation conversation) { FileTransfer file_transfer = new FileTransfer(); file_transfer.account = conversation.account; file_transfer.counterpart = conversation.counterpart; @@ -49,11 +49,11 @@ public class FileManager : StreamInteractionModule, Object { file_transfer.file_name = file_info.get_display_name(); file_transfer.mime_type = file_info.get_content_type(); file_transfer.size = (int)file_info.get_size(); - file_transfer.input_stream = file.read(); + file_transfer.input_stream = yield file.read_async(); } catch (Error e) { file_transfer.state = FileTransfer.State.FAILED; } - save_file(file_transfer); + yield save_file(file_transfer); file_transfer.persist(db); @@ -162,16 +162,16 @@ public class FileManager : StreamInteractionModule, Object { } } - private void save_file(FileTransfer file_transfer) { + private async void save_file(FileTransfer file_transfer) { try { string filename = Random.next_int().to_string("%x") + "_" + file_transfer.file_name; File file = File.new_for_path(Path.build_filename(get_storage_dir(), filename)); OutputStream os = file.create(FileCreateFlags.REPLACE_DESTINATION); - os.splice(file_transfer.input_stream, 0); + yield os.splice_async(file_transfer.input_stream, 0); os.close(); file_transfer.state = FileTransfer.State.COMPLETE; file_transfer.path = filename; - file_transfer.input_stream = file.read(); + file_transfer.input_stream = yield file.read_async(); } catch (Error e) { file_transfer.state = FileTransfer.State.FAILED; } |