我正在按照 IPFS github示例保存到 IPFS:
'use strict'
const IPFS = require('ipfs')
const all = require('it-all')
async function main () {
const node = await IPFS.create()
const version = await node.version()
console.log('Version:', version.version)
for await (const file of await node.add({
path: 'hello.txt',
content: Buffer.from('Hello World 101') //<<<=== why Buffer before assigned to content?
})) {
console.log('Added file:', file.path, file.cid.toString())
const data = Buffer.concat(await all(node.cat(file.cid)))
console.log('Added file contents:', data.toString())
}
}
main()
Buffer
我注意到字符串在保存之前被转换为二进制。有人可以解释一下这里的用法Buffer
吗?保存图像或视频文件怎么样?