-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from ltfschoen/luke/save-website-filecoin
wip: Try to save current Website IPFS Hash to FFS storage
- Loading branch information
Showing
4 changed files
with
154 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Source: https://developers.google.com/web/updates/2012/06/How-to-convert-ArrayBuffer-to-and-from-String | ||
function arrayBufferToString(buf) { | ||
return String.fromCharCode.apply(null, new Uint8Array(buf)); | ||
} | ||
|
||
function stringToArrayBuffer(str) { | ||
var buf = new ArrayBuffer(str.length * 2); // 2 bytes for each char | ||
var bufView = new Uint8Array(buf); | ||
for (var i = 0, strLen = str.length; i < strLen; i++) { | ||
bufView[i] = str.charCodeAt(i); | ||
} | ||
return buf; | ||
} | ||
|
||
function toByteArray(hexString) { | ||
var result = []; | ||
for (var i = 0; i < hexString.length; i += 2) { | ||
result.push(parseInt(hexString.substr(i, 2), 16)); | ||
} | ||
return result; | ||
} | ||
|
||
function toHexString(byteArray) { | ||
return Array.prototype.map.call(byteArray, function(byte) { | ||
return ('0' + (byte & 0xFF).toString(16)).slice(-2); | ||
}).join(''); | ||
} | ||
|
||
export { | ||
arrayBufferToString, | ||
stringToArrayBuffer, | ||
toByteArray, | ||
toHexString, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters