Skip to content
This repository has been archived by the owner on Jan 7, 2020. It is now read-only.

Switch XorNames from ref-array to JS Array #64

Merged
merged 2 commits into from
Apr 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/api/emulations/nfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ class File {
**/
constructor(ref) {
this._ref = ref;
if (Array.isArray(ref.data_map_name)) {
// translate the incoming array back into a buffer we can use internally
this._ref.data_map_name = t.XOR_NAME(ref.data_map_name);
}
}

get ref() {
Expand All @@ -28,8 +32,8 @@ class File {
modified_sec: this._ref.modified_sec,
modified_nsec: this._ref.modified_nsec,
size: this._ref.size,
data_map_name: this._ref.data_map_name,
user_metadata_ptr: this._ref.data_map_name.ref(),
data_map_name: this.dataMapName,
user_metadata_ptr: this.dataMapName.ref(),
user_metadata_len: 0,
user_metadata_cap: 0
};
Expand Down Expand Up @@ -156,7 +160,7 @@ class NFS {
**/
update(fileName, file, version) {
return lib.file_update(this.mData.app.connection, this.mData.ref, fileName,
file.ref.ref(), version)
file.ref.ref(), version)
.then(() => file);
}
}
Expand Down
12 changes: 11 additions & 1 deletion src/native/_immutable.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ function translateXorName(appPtr, str) {
} else {
name = str;
}
} else if (Array.isArray(str)) {
name = t.XOR_NAME(str).ref().readPointer(0)
} else {
const b = new Buffer(str);
if (b.length != 32) throw Error("XOR Names _must be_ 32 bytes long.")
Expand All @@ -26,6 +28,14 @@ function translateXorName(appPtr, str) {
return [appPtr, name]
}

function copyFromRefArray(refArray){
let target = [];
for (var i = 0; i < refArray.length; i++) {
target.push(refArray[i])
}
return target;
}


module.exports = {
types: {
Expand All @@ -50,7 +60,7 @@ module.exports = {
}, null),
idata_close_self_encryptor: h.Promisified(null, 'pointer',
// make a copy to ensure the data stays around
resp => t.XOR_NAME(ref.reinterpret(resp[0], 32))),
resp => copyFromRefArray(t.XOR_NAME(ref.reinterpret(resp[0], 32)))),
idata_fetch_self_encryptor: h.Promisified(translateXorName, SEReadHandle),
idata_size: h.Promisified(null, t.u64),
idata_read_from_self_encryptor: h.Promisified(null, [t.u8Pointer, t.usize, t.usize], h.asBuffer),
Expand Down
2 changes: 1 addition & 1 deletion test/immutable.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('Immutable Data', () => {
})));
});

it.skip('store address in a MD', () => {
it('store address in a MD', () => {
const testString = `test-${Math.random()}`;
const testXorName = h.createRandomXorName();

Expand Down