-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Completely remove buffer from browser
- Loading branch information
1 parent
d52c111
commit 5542130
Showing
14 changed files
with
2,900 additions
and
93 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,31 @@ | ||
const swarm = require("./..").at("http://swarm-gateways.net"); | ||
|
||
(async () => { | ||
try { | ||
// Uploading raw data | ||
const file = "this is a test"; | ||
const fileHash = await swarm.upload(new Buffer(file)) | ||
console.log("Uploaded file. SwarmHash:", fileHash); | ||
|
||
// Uploading raw data | ||
const file = "this is a test"; | ||
const fileHash = await swarm.upload(new Buffer(file)) | ||
console.log("Uploaded file. SwarmHash:", fileHash); | ||
//// Downloading raw data | ||
const fileBuffer = await swarm.download(fileHash); | ||
console.log("Downloaded file. Contents:", swarm.toString(fileBuffer)); | ||
|
||
// Downloading raw data | ||
const fileBuffer = await swarm.download(fileHash); | ||
console.log("Downloaded file. Contents:", fileBuffer.toString()); | ||
// Uploading directory | ||
const dir = { | ||
"/foo.txt": {type: "text/plain", data: "this is foo.txt"}, | ||
"/bar.txt": {type: "text/plain", data: "this is bar.txt"} | ||
}; | ||
const dirHash = await swarm.upload(dir); | ||
console.log("Uploaded directory. SwarmHash:", dirHash); | ||
|
||
// Uploading directory | ||
const dir = { | ||
"/foo.txt": {type: "text/plain", data: new Buffer("this is foo.txt")}, | ||
"/bar.txt": {type: "text/plain", data: new Buffer("this is bar.txt")} | ||
}; | ||
const dirHash = await swarm.upload(dir); | ||
console.log("Uploaded directory. SwarmHash:", dirHash); | ||
|
||
//// Downloaading a directory | ||
const dirObj = await swarm.download(dirHash); | ||
console.log("Downloaded directory. Contents:"); | ||
for (let path in dirObj) | ||
console.log("-", path, ":", dirObj[path].data.toString()); | ||
//// Downloaading a directory | ||
const dirObj = await swarm.download(dirHash); | ||
console.log("Downloaded directory. Contents:"); | ||
for (let path in dirObj) | ||
console.log("-", path, ":", swarm.toString(dirObj[path].data)); | ||
} catch (e) { | ||
console.log(e); | ||
} | ||
|
||
})(); |
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
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
Oops, something went wrong.