[gnome-games] utils: Add DataInputStream



commit 824eefd319a5568f38ef49acc924cc76e5b4791d
Author: Adrien Plazas <kekun plazas laposte net>
Date:   Thu Jan 26 09:57:34 2017 +0100

    utils: Add DataInputStream
    
    This will be used in the next commit to check if some data is in an
    input stream.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=777777

 src/Makefile.am                  |    1 +
 src/utils/data-input-stream.vala |   19 +++++++++++++++++++
 2 files changed, 20 insertions(+), 0 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 1d8d3d6..5ff086c 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -131,6 +131,7 @@ gnome_games_SOURCES = \
        utils/cue-sheet/cue-sheet-file-node.vala \
        utils/cue-sheet/cue-sheet-track-mode.vala \
        utils/cue-sheet/cue-sheet-track-node.vala \
+       utils/data-input-stream.vala \
        utils/directory.vala \
        utils/filename-title.vala \
        utils/fingerprint.vala \
diff --git a/src/utils/data-input-stream.vala b/src/utils/data-input-stream.vala
new file mode 100644
index 0000000..8a71e55
--- /dev/null
+++ b/src/utils/data-input-stream.vala
@@ -0,0 +1,19 @@
+// This file is part of GNOME Games. License: GPLv3
+
+public class Games.DataInputStream : Object {
+       private File file;
+
+       public DataInputStream (File file) {
+               this.file = file;
+       }
+
+       public bool has_data (size_t offset, uint8[] value) throws Error {
+               var stream = file.read ();
+               stream.seek (offset, SeekType.SET);
+
+               var buffer = new uint8[value.length];
+               stream.read (buffer);
+
+               return Memory.cmp (value, buffer, value.length) == 0;
+       }
+}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]