[gnome-games] utils: Add FingerprintUid.for_chunk()
- From: Adrien Plazas <aplazas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games] utils: Add FingerprintUid.for_chunk()
- Date: Wed, 17 Aug 2016 20:21:16 +0000 (UTC)
commit 59fc041668a118e2686ad0a5c959bfb63dc21c16
Author: Adrien Plazas <kekun plazas laposte net>
Date: Thu Aug 4 09:36:30 2016 +0200
utils: Add FingerprintUid.for_chunk()
This will be used in the next commit to create an UID by hashing only
the header of a Mega-CD disc.
https://bugzilla.gnome.org/show_bug.cgi?id=769474
src/utils/fingerprint.vala | 30 +++++++++++++++++++++++-------
1 files changed, 23 insertions(+), 7 deletions(-)
---
diff --git a/src/utils/fingerprint.vala b/src/utils/fingerprint.vala
index 0c28482..ecea389 100644
--- a/src/utils/fingerprint.vala
+++ b/src/utils/fingerprint.vala
@@ -1,18 +1,23 @@
// This file is part of GNOME Games. License: GPLv3
namespace Games.Fingerprint {
- private string get_for_file_uri (string uri) throws Error {
+ private string get_for_file_uri (string uri, size_t start, size_t? length) throws Error {
var file = File.new_for_uri (uri);
var istream = file.read ();
- return get_for_file_input_stream (istream);
+ return get_for_file_input_stream (istream, start, length);
}
- private string get_for_file_input_stream (FileInputStream file_stream) throws Error {
- file_stream.seek (0, SeekType.END);
- var size = (size_t) file_stream.tell ();
+ private string get_for_file_input_stream (FileInputStream file_stream, size_t start, size_t? length)
throws Error {
+ size_t size;
+ if (length == null) {
+ file_stream.seek (0, SeekType.END);
+ size = (size_t) file_stream.tell ();
+ }
+ else
+ size = length;
- file_stream.seek (0, SeekType.SET);
+ file_stream.seek (start, SeekType.SET);
var bytes = file_stream.read_bytes (size);
return Checksum.compute_for_bytes (ChecksumType.MD5, bytes);
@@ -22,18 +27,29 @@ namespace Games.Fingerprint {
public class Games.FingerprintUid: Object, Uid {
private string uri;
private string prefix;
+ private size_t start;
+ private size_t? length;
private string uid;
public FingerprintUid (string uri, string prefix) {
this.uri = uri;
this.prefix = prefix;
+ start = 0;
+ length = null;
+ }
+
+ public FingerprintUid.for_chunk (string uri, string prefix, size_t start, size_t length) {
+ this.uri = uri;
+ this.prefix = prefix;
+ this.start = start;
+ this.length = length;
}
public string get_uid () throws Error {
if (uid != null)
return uid;
- var fingerprint = Fingerprint.get_for_file_uri (uri);
+ var fingerprint = Fingerprint.get_for_file_uri (uri, start, length);
uid = @"$prefix-$fingerprint";
return uid;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]