blockstackblockstack-Trans

CodingBasic - Work with Storage

2019-07-24  本文已影响7人  空乱木

From : https://docs.blockstack.org/develop/storage.html

Blockstack平台将应用程序数据存储在Gaia存储系统中。事务元数据存储在blockstack区块链上,用户应用程序数据存储在Gaia存储中。在区块链之外存储数据可以确保blockstack应用程序可以为用户提供高性能和高可用性的数据读写,而不需要引入中央信任方。

创建一个文件
创建加密文件
阅读文件
读取加密文件
读取其他用户的未加密文件
删除一个文件

Note:
Blockstack Gaia存储api和磁盘格式将在即将发布的预发行版中改变,打破向后兼容性。文件加密目前是按文件选择加入的。

某些存储特性,如集合,在当前版本中没有实现。这些特性将在未来的更新中推出。

创建一个文件

您使用UserSession.putFile

var userSession = new UserSession()
let options = {
encrypt: false
}
userSession.putFile("/hello.txt", "hello world!", options)
.then(() => {
// /hello.txt exists now, and has the contents "hello world!”.
})

创建加密文件

使用

var userSession = new UserSession()
let options = {
encrypt: true
}
userSession.putFile("/message.txt", "Secret hello!", options)
.then(() => {
// message.txt exists now, and has the contents "hello world!”.
})

读取文件

使用

var userSession = new UserSession()
let options = {
decrypt: false
}
userSession.getFile("/hello.txt", options)
.then((fileContents) => {
// get the contents of the file /hello.txt
assert(fileContents === "hello world!”)
});

读取加密文件

var userSession = new UserSession()
let options = {
decrypt: true
}
userSession.getFile("/message.txt", options)
.then((fileContents) => {
// get & decrypt the contents of the file /message.txt
assert(fileContents === "Secret hello!”)
});

读取其他用户的未加密文件

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
}
var userSession = new UserSession()
userSession.putFile("/hello.txt", "hello world!", options)
.then((fileContents) => {
// get the contents of the file /message.txt
assert(fileContents === "hello world!”)
});

删除一个文件

从应用程序的数据存储中使用UserSession.deleteFile。

var userSession = new UserSession()
userSession.deleteFile("/hello.txt”)
.then(() => {
// /hello.txt is now removed.
})

相关信息

要了解更多关于Gaia提供的保证,请参阅存储写和读

image.png

Rebase是一个全球性的去中心化组织,致力于帮助极客更好地利用科技创新,推动社会变革。Rebase社区聚集着一群拥有不同技能的人,他们通过贡献自己的时间和智慧来为社区的发展添砖加瓦,用实际的行动来尝试社区和社会自治的可能。

招募志愿者

Rebase作为一个开放的社区,我们欢迎不同的人加入我们,你将有机会:

•探索新的有趣的项目
•认识一群志同道合的人
•接触到行业内最前沿的知识
•与技术领袖交流的机会
•结识未来的创业伙伴

参与的形式可以是多种多样的,哪怕不在同一个城市,在这里你可以:

•策划一场知识密度极高的分享会
•组织一次酷炫的线下区块链workshop
•设计一款脑洞大开的海报
•开发一个方便易用的工具

更多好玩的东西,我们一起探索。

上一篇 下一篇

猜你喜欢

热点阅读