Skip to content

Commit

Permalink
Fix Blob content tpye not parsed correctly
Browse files Browse the repository at this point in the history
Added getBlob method to query result
  • Loading branch information
Rudiksz committed Jul 25, 2020
1 parent d03f2c3 commit dc597fb
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
17 changes: 11 additions & 6 deletions lib/src/blob.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class Blob {
Blob.data(this._contentType, this._data);

Blob._fromMap(Map<String, dynamic> map) {
this._contentType = map["contentType"];
this._contentType = map["content_type"];
this._digest = map["digest"];
this._length = map["length"];
}
Expand All @@ -21,24 +21,29 @@ class Blob {
String get contentType => _contentType;
String get digest => _digest;
int get length => _length;

set dbName(String dbName) => this._dbname = dbName;
set documentID(String id) => this._documentID = id;
set documentKey(String key) => this._documentKey = key;

Future<Uint8List> get content async {
if (_shouldLoadData) {
return await Database._methodChannel.invokeMethod(
if (_data == null) {
_data = await Database._methodChannel.invokeMethod(
'getBlobContentFromDocumentWithId', <String, dynamic>{
'database': _dbname,
'id': _documentID,
'key': _documentKey,
'digest': _digest
});
} else {
return _data;
}

return _data;
}

/// Gets content of the current object as a Dictionary.
///
/// - Returns: The Dictionary representing the content of the current object.
Map<String, dynamic> toMap() {
return {"contentType": _contentType, "data": _data, "@type": "blob"};
return {"content_type": _contentType, "data": _data, "@type": "blob"};
}
}
2 changes: 1 addition & 1 deletion lib/src/document.dart
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class Document {
Map<String, dynamic> _result = getMap(key);
if (_result is Map && _result["@type"] == "blob") {
if (_result.containsKey("data")) {
return Blob.data(_result["contentType"], _result["data"]);
return Blob.data(_result["content_type"], _result["data"]);
} else {
var _blob = Blob._fromMap(_result);
_blob._dbname = _dbname;
Expand Down
15 changes: 14 additions & 1 deletion lib/src/query/result.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
part of couchbase_lite;

class Result {
Result.fromMap(Map<String, dynamic> map) {
this._internalMap = map;
}

Result();

Map<String, dynamic> _internalMap = {};
List<dynamic> _internalList = [];

Expand Down Expand Up @@ -33,7 +39,14 @@ class Result {
}
}

//TODO: implement getBlob()
Blob getBlob({int index, String key}) {
var result = getValue(index: index, key: key);
if (null != result) {
return Blob._fromMap(result);
} else {
return null;
}
}

bool getBoolean({int index, String key}) {
var result = getValue(index: index, key: key);
Expand Down

0 comments on commit dc597fb

Please sign in to comment.