mirror of https://github.com/lukechilds/docs.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
127 lines
3.5 KiB
127 lines
3.5 KiB
6 years ago
|
---
|
||
5 years ago
|
|
||
|
|
||
6 years ago
|
---
|
||
5 years ago
|
# Guide to Blockstack Storage
|
||
6 years ago
|
|
||
|
{:.no_toc}
|
||
|
|
||
|
The Blockstack Platform stores application data in the Gaia Storage System. Transactional metadata is stored on the Blockstack blockchain and user application data is stored in Gaia storage. Storing data off of the blockchain ensures that Blockstack applications can provide users with high performance and high availability for data reads and writes without introducing central trust parties.
|
||
|
|
||
|
* TOC
|
||
|
{:toc}
|
||
|
|
||
|
|
||
6 years ago
|
{% include note.html content="<ul> <li>Blockstack Gaia Storage APIs and on-disk format will change in upcoming pre-releases breaking backward compatibility. File encryption is currently opt-in on a file by file basis.</li> <li>Certain storage features such as collections are not implemented in the current version. These features will be rolled out in future updates.</li> </ul>" %}
|
||
6 years ago
|
|
||
5 years ago
|
## How data is stored
|
||
|
|
||
|
Gaia storage is a key-value store.
|
||
|
|
||
6 years ago
|
|
||
|
## Creating a file
|
||
|
|
||
|
You use the <a href="https://blockstack.github.io/blockstack.js/classes/usersession.html#putfile" target="_blank">UserSession.putFile</a>
|
||
|
|
||
|
```JavaScript
|
||
6 years ago
|
var userSession = new UserSession()
|
||
6 years ago
|
let options = {
|
||
|
encrypt: false
|
||
|
}
|
||
6 years ago
|
userSession.putFile("/hello.txt", "hello world!", options)
|
||
6 years ago
|
.then(() => {
|
||
|
// /hello.txt exists now, and has the contents "hello world!".
|
||
|
})
|
||
|
```
|
||
|
|
||
|
## Creating an encrypted file
|
||
|
|
||
|
You use the <a href="https://blockstack.github.io/blockstack.js/classes/usersession.html#putfile" target="_blank"></a>
|
||
|
|
||
|
```JavaScript
|
||
6 years ago
|
var userSession = new UserSession()
|
||
|
|
||
6 years ago
|
let options = {
|
||
|
encrypt: true
|
||
|
}
|
||
|
|
||
6 years ago
|
userSession.putFile("/message.txt", "Secret hello!", options)
|
||
6 years ago
|
.then(() => {
|
||
|
// message.txt exists now, and has the contents "hello world!".
|
||
|
})
|
||
|
```
|
||
|
|
||
|
## Reading a file
|
||
|
|
||
|
You use the <a href="https://blockstack.github.io/blockstack.js/classes/usersession.html#getfile" target="_blank"></a>
|
||
|
|
||
|
```JavaScript
|
||
6 years ago
|
var userSession = new UserSession()
|
||
|
|
||
6 years ago
|
let options = {
|
||
|
decrypt: false
|
||
|
}
|
||
|
|
||
6 years ago
|
userSession.getFile("/hello.txt", options)
|
||
6 years ago
|
.then((fileContents) => {
|
||
|
// get the contents of the file /hello.txt
|
||
|
assert(fileContents === "hello world!")
|
||
|
});
|
||
|
```
|
||
|
|
||
|
## Reading an encrypted file
|
||
|
|
||
|
You use the <a href="" target="_blank"></a>
|
||
|
|
||
|
```JavaScript
|
||
6 years ago
|
var userSession = new UserSession()
|
||
|
|
||
6 years ago
|
let options = {
|
||
|
decrypt: true
|
||
|
}
|
||
|
|
||
6 years ago
|
userSession.getFile("/message.txt", options)
|
||
6 years ago
|
.then((fileContents) => {
|
||
|
// get & decrypt the contents of the file /message.txt
|
||
|
assert(fileContents === "Secret hello!")
|
||
|
});
|
||
|
```
|
||
|
|
||
|
## Reading another user's unencrypted file
|
||
|
In order for files to be publicly readable, the app must request
|
||
|
the `publish_data` scope during authentication.
|
||
|
|
||
|
```JavaScript
|
||
|
let options = {
|
||
|
user: 'ryan.id', // the Blockstack ID of the user for which to lookup the file
|
||
|
app: 'http://BlockstackApp.com' // origin of the app this file is stored for
|
||
|
}
|
||
|
|
||
6 years ago
|
var userSession = new UserSession()
|
||
|
userSession.putFile("/hello.txt", "hello world!", options)
|
||
6 years ago
|
.then((fileContents) => {
|
||
|
// get the contents of the file /message.txt
|
||
|
assert(fileContents === "hello world!")
|
||
|
});
|
||
|
```
|
||
|
|
||
|
## Delete a file
|
||
|
|
||
6 years ago
|
You use the <a href="https://blockstack.github.io/blockstack.js/classes/usersession.html#deletefile" target="_blank">UserSession.deleteFile</a> from the application's data store.
|
||
6 years ago
|
|
||
|
|
||
|
```JavaScript
|
||
6 years ago
|
|
||
|
var userSession = new UserSession()
|
||
|
|
||
|
userSession.deleteFile("/hello.txt")
|
||
6 years ago
|
.then(() => {
|
||
|
// /hello.txt is now removed.
|
||
|
})
|
||
|
```
|
||
6 years ago
|
|
||
|
## Related Information
|
||
|
{:.no_toc}
|
||
|
|
||
|
To learn more about the guarantees provided by Gaia, see [Storage write and read]({{ site.baseurl }}/storage/write-to-read.html#)
|