{"id":22165587,"url":"https://github.com/textileio/go-buckets","last_synced_at":"2025-07-26T11:32:10.265Z","repository":{"id":51082231,"uuid":"342642048","full_name":"textileio/go-buckets","owner":"textileio","description":"File and dynamic directory storage built on Threads, IPFS, and LibP2P","archived":false,"fork":false,"pushed_at":"2021-05-24T18:09:56.000Z","size":10694,"stargazers_count":14,"open_issues_count":1,"forks_count":5,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-06-19T04:10:59.088Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/textileio.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-02-26T16:58:03.000Z","updated_at":"2023-04-10T09:51:04.000Z","dependencies_parsed_at":"2022-08-20T03:10:36.114Z","dependency_job_id":null,"html_url":"https://github.com/textileio/go-buckets","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/textileio%2Fgo-buckets","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/textileio%2Fgo-buckets/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/textileio%2Fgo-buckets/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/textileio%2Fgo-buckets/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/textileio","download_url":"https://codeload.github.com/textileio/go-buckets/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227673973,"owners_count":17802303,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-02T05:15:37.338Z","updated_at":"2024-12-02T05:15:38.230Z","avatar_url":"https://github.com/textileio.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# go-buckets\n\n[![Made by Textile](https://img.shields.io/badge/made%20by-Textile-informational.svg?style=popout-square)](https://textile.io)\n[![Chat on Slack](https://img.shields.io/badge/slack-slack.textile.io-informational.svg?style=popout-square)](https://slack.textile.io)\n[![GitHub license](https://img.shields.io/github/license/textileio/go-buckets.svg?style=popout-square)](./LICENSE)\n[![GitHub action](https://github.com/textileio/go-buckets/workflows/Test/badge.svg?style=popout-square)](https://github.com/textileio/go-buckets/actions)\n[![standard-readme compliant](https://img.shields.io/badge/readme%20style-standard-brightgreen.svg?style=popout-square)](https://github.com/RichardLitt/standard-readme)\n\n\u003e File and dynamic directory storage built on Threads, IPFS, and LibP2P\n\nJoin us on our [public Slack channel](https://slack.textile.io/) for news, discussions, and status updates. [Check out our blog](https://medium.com/textileio) for the latest posts and announcements.\n\n### WARNING: This repo is pointing to a [feature branch](https://github.com/textileio/go-threads/pull/498) of `go-threads` that handles identities as Decentralized Identifiers (DIDs) and should be considered alpha. The [textile repo](https://github.com/textileio/textile) contains the non-DID-based bucket implementation currently compatible with [Textile's public hub](https://cloud.hub.textile.io/#/access). DID-based buckets will be integrated into the hub mid 2021. In the meantime, you can still use this repo for standalone bucket peers.\n\n## Table of Contents\n\n- [Security](#security)\n- [Background](#background)\n- [Install](#install)\n  - [Buckets Core](#buckets-core)\n  - [gRPC Daemon](#grpc-daemon)\n  - [gRPC Client](#grpc-client)\n  - [Client CLI](#client-cli)\n  - [Local-first Library](#local-first-library)\n- [Getting Started](#getting-started)\n  - [Running Buckets](#running-buckets)\n  - [Creating a bucket](#creating-a-bucket)\n  - [Creating a private bucket](#creating-a-private-bucket)\n  - [Adding files and folders to a bucket](#adding-files-and-folders-to-a-bucket)\n  - [Recreating an existing bucket](#recreating-an-existing-bucket)\n  - [Creating a bucket from an existing Cid](#creating-a-bucket-from-an-existing-cid)\n  - [Exploring bucket contents](#exploring-bucket-contents)\n  - [Resetting bucket contents](#resetting-bucket-contents)\n  - [Watching a bucket for changes](#watching-a-bucket-for-changes)\n  - [Protecting a file with a password](#protecting-a-file-with-a-password)\n  - [Sharing bucket files and folders](#sharing-bucket-files-and-folders)\n  - [Multi-writer buckets](#multi-writer-buckets)\n  - [Deleting a bucket](#deleting-a-bucket)\n- [Using the Local Library](#using-the-local-library)\n  - [Creating a bucket](#creating-a-bucket-1)\n  - [Getting an existing bucket](#getting-an-existing-bucket)\n  - [Pushing local files](#pushing-local-files)\n  - [Pulling remote changes](#pulling-remote-changes)\n- [Developing](#developing)\n- [Contributing](#contributing)\n- [Changelog](#changelog)\n- [License](#license)\n\n## Security\n\nBuckets is still under heavy development and no part of it should be used before a thorough review of the underlying code and an understanding APIs and protocols may change rapidly. There may be coding mistakes, and the underlying protocols may contain design flaws. Please [let us know](mailto:contact@textile.io) immediately if you have discovered a security vulnerability.\n\nPlease also read the [security note](https://github.com/ipfs/go-ipfs#security-issues) for [go-ipfs](https://github.com/ipfs/go-ipfs).\n\n## Background\n\nBuckets function a bit like S3 buckets. They're a virtual filesystem where you can push, pull, list, and cat files. You can share them via web links or render the whole thing as a website or web app. They also function a bit like a Git repository. The point of entry is from a folder on your local machine that is synced to a _remote_.\n\nAt a lower level, buckets provide a dynamic wrapper around [UnixFS]([UnixFS](https://github.com/ipfs/go-unixfs)) directories with auto-updating IPNS, static website rendering, access control, and encryption. Since buckets are just ThreadDB collection _instances_ (see [go-threads](https://github.com/textileio/go-threads)), they automatically leverage the distributed nature of ThreadDB by allowing multiple identities to write to the same bucket hosted by different Libp2p hosts.\n\n## Install\n\n### Buckets Core\n\n```\ngo get github.com/textileio/go-buckets\n```\n\n### gRPC Daemon\n\n-   **Prebuilt package**: See [release assets](https://github.com/textileio/go-buckets/releases/latest)\n-   **Docker image**: See the `buckets` tag on [Docker Hub](https://hub.docker.com/r/textile/go-buckets/tags)\n-   **Build from the source**: \n\n```\ngit clone https://github.com/textileio/go-buckets\ncd go-buckets\ngo get ./cmd/buckd\n```\n\n### gRPC Client\n\n```\ngo get github.com/textileio/go-buckets/api/client\n```\n\n### Client CLI\n\n-   **Prebuilt package**: See [release assets](https://github.com/textileio/go-buckets/releases/latest)\n-   **Build from the source**: \n\n```\ngit clone https://github.com/textileio/go-buckets\ncd go-buckets\ngo get ./cmd/buck\n```\n\n### Local-first Library\n\n```\nimport \"github.com/textileio/go-buckets/local\"\n```\n\nSee [Using the Local Library](#using-the-local-library) for more info.\n\n## Getting Started\n\nThis section focusses on interacting with buckets using a local daemon and the `buck` CLI. If your application doesn't require a daemon, you can use the [core library](https://github.com/textileio/go-buckets/blob/master/buckets.go) directly.\n\n### Running Buckets\n\nThe `buckd` daemon can be run as a server or alongside desktop apps or command-line tools. The easiest way to run `buckd` is by using the provided Docker Compose files. If you're new to Docker and/or Docker Compose, get started [here](https://docs.docker.com/compose/gettingstarted/). You should have `docker-compose` in your `PATH`.\n\nCreate an `.env` file and add the following values:  \n\n```\nREPO_PATH=~/myrepo\nBUCK_LOG_DEBUG=true\n```\n\nCopy [this compose file](https://github.com/textileio/go-buckets/blob/master/cmd/buckd/docker-compose.yml) and run it with the following command.\n\n```\ndocker-compose -f docker-compose.yml up\n```\n\nCongrats! Now you have Buckets running locally.\n\nThe Docker Compose file starts an IPFS node, which is used to pin bucket files and folders. You could point `buckd` to a different (possibly remote) IPFS node by setting the `BUCK_IPFS_MULTIADDR` variable to a different multiaddress.\n\n### Creating a bucket\n\nFirst off, take a look at `buck --help`.\n\n```\nThe Bucket Client.\n\nManages files and folders in an object storage bucket.\n\nUsage:\n  buck [command]\n\nAvailable Commands:\n  add         Add adds a UnixFs DAG locally at path\n  cat         Cat bucket objects at path\n  decrypt     Decrypt bucket objects at path with password\n  destroy     Destroy bucket and all objects\n  encrypt     Encrypt file with a password\n  help        Help about any command\n  init        Initialize a new or existing bucket\n  links       Show links to where this bucket can be accessed\n  ls          List top-level or nested bucket objects\n  pull        Pull bucket object changes\n  push        Push bucket object changes\n  root        Show bucket root CIDs\n  status      Show bucket object changes\n  watch       Watch auto-pushes local changes to the remote\n\nFlags:\n      --api string   API target (default \"127.0.0.1:3006\")\n  -h, --help         help for buck\n\nUse \"buck [command] --help\" for more information about a command.\n```\n\nTo get started, initialize a new bucket.\n\n```\nmkdir mybucket \u0026\u0026 cd mybucket\nbuck init\n```\n\nWhen prompted, give your bucket a name and either opt-in or decline bucket encyption (see [Creating a private bucket](#creating-a-private-bucket) for more about bucket encryption).\n\nYou should now see two links for the new bucket on the locally running gateway.\n\n```\n\u003e http://127.0.0.1:8000/thread/bafkq3ocmdkrljadlgybtvocytpdw4hbnzygxecxehdp7pfj32lxp34a/buckets/bafzbeifyzfm3kosie25s5qthvvcjrr42ivd7doqhwvu5m4ks7uqv4j5lyi Thread link\n\u003e http://127.0.0.1:8000/ipns/bafzbeifyzfm3kosie25s5qthvvcjrr42ivd7doqhwvu5m4ks7uqv4j5lyi IPNS link (propagation can be slow)\n\u003e Success! Initialized /path/to/mybucket as a new empty bucket\n```\n\nThe first URL is the link to the ThreadDB instance. Internally, a collection named `buckets` is created. Each new instance in this collection amounts to a new bucket. However, when you visit this link, you'll notice a custom file browser. This is because the gateway considers the built-in `buckets` collection a special case. You can still view the raw ThreadDB instance by appending `?json=true` to the URL.\n\nThe second URL is the bucket's unique IPNS address, which is auto-updated when you add, modify, or delete files.\n\nIf you have configured the daemon with DNS settings, you will see a third URL that links to the bucket's WWW address, where it is rendered as a static website / client-side application. See `buckd --help` for more info.\n\n**Important**: If your bucket is private (encrypted), an access token (JWT) will be appended to these links. This token represents your _identity_ across ***all buckets*** and should not be shared without caution.\n\n`buck init` created a configuration folder in `mybucket` called `.textile`. This folder is somewhat like a `.git` folder, as it contains information about the bucket's remote address and local state.\n\n`.textile/config.yml` will look something like,\n\n```\nkey: bafzbeifyzfm3kosie25s5qthvvcjrr42ivd7doqhwvu5m4ks7uqv4j5lyi\nthread: bafkq3ocmdkrljadlgybtvocytpdw4hbnzygxecxehdp7pfj32lxp34a\n```\n\nWhere `key` is the bucket's unique key, and `thread` is it's ThreadDB ID.\n\nAdditionally, `.textile/repo` contains a repository describing the current file structure, which is used to stage changes against the remote.\n\n### Creating a private bucket\n\nBucket encryption (AES-CTR + AES-512 HMAC) happens entirely within the `buckd`, meaning your data gets encrypted on the way in, and decrypted on the way out. This type of encryption has two goals:\n\n- Obfuscate bucket data / files (the normal goal of encryption)\n- Obfuscate directory structure, which amounts to encrypting [IPLD](https://ipld.io/) nodes and their links.\n\nAs a result of these goals, we refer to encrypted buckets as _private buckets_. Read more about bucket encryption [here](https://docs.textile.io/buckets/#encryption).\n\nTo create a new private bucket, use the `--private` flag with `buck` init or respond `y` when prompted.\n\nIn addition to bucket-level encryption, you can also [protect a file with a password](#protecting-a-file-with-a-password).\n\n### Adding files and folders to a bucket\n\nBucket files and folders are content-addressed by Cids. Check out [the spec](https://github.com/multiformats/cid) if you're unfamiliar with Cids.\n\n`buck` stages new files as additions:\n\n```\necho \"hello world\" \u003e hello.txt\nbuck status\n\u003e new file:  hello.txt\n```\n\n`buck status` is powered by DAG-based diffing. Much like `git`, this allows buck to only push and pull _changes_. Read more about bucket diffing in the [docs](https://docs.textile.io/buckets/#diffing-and-synching), or check out this [in-depth blog post](https://blog.textile.io/buckets-diffing-syncing-archiving/).\n\nUse `push` to sync the change.\n\n```\nbuck push\n+ hello.txt: bafkreifjjcie6lypi6ny7amxnfftagclbuxndqonfipmb64f2km2devei4\n\u003e bafybeihm4zrnrsdroazwsvk3i65ooqzdftaugdkjiedr6ocq65u3ap4wni\n```\n\nThe output shows the Cid of the added file and the bucket's new root Cid.\n\n`push` will sync all types of file changes: _Additions, modifications, and deletions_.\n\n### Recreating an existing bucket\n\nIt's often useful to recreate a bucket from the remote. This is somewhat like re-cloning a Git repo. This can be done in a different location on the same machine, or, if `buckd` has a public IP address, from a completely different machine.\n\nLet's recreate the bucket from the previous step in a new directory.\n\n```\nmkdir mybucket2 \u0026\u0026 cd mybucket2\nbuck init --existing\n```\n\nThe `--existing` flag allows for interactively selecting an existing bucket to initialize from.\n\n```\n? Which exiting bucket do you want to init from?:\n  ▸ MyBucket bafzbeifyzfm3kosie25s5qthvvcjrr42ivd7doqhwvu5m4ks7uqv4j5lyi\n```\n\nAt this point, there's only one bucket to choose from.\n\n```\n\u003e Selected bucket MyBucket\n+ hello.txt: bafkreifjjcie6lypi6ny7amxnfftagclbuxndqonfipmb64f2km2devei4\n+ .textileseed: bafkreifbdzttoqsch5j66hfmcbsic6qvwrikibgzfbg3tn7rc3j63ukk3u\n\u003e Your bucket links:\n\u003e http://127.0.0.1:8000/thread/bafkq3ocmdkrljadlgybtvocytpdw4hbnzygxecxehdp7pfj32lxp34a/buckets/bafzbeifyzfm3kosie25s5qthvvcjrr42ivd7doqhwvu5m4ks7uqv4j5lyi Thread link\n\u003e http://127.0.0.1:8000/ipns/bafzbeifyzfm3kosie25s5qthvvcjrr42ivd7doqhwvu5m4ks7uqv4j5lyi IPNS link (propagation can be slow)\n\u003e Success! Initialized /path/to/mybucket2 from an existing bucket\n```\n\nJust as before, the output shows the bucket's remote links. However, in this case `init` also pulled down the content.\n\n**Note**: `.textileseed` is used to randomize a bucket's top level Cid and cannot be modified.\n\nThe `--existing` flag is really just a helper that sets the `--thread` and `--key` flags, which match the config values we saw earlier. We could have used those flags directly to achieve the same result.\n\n```\nbuck init --thread bafkq3ocmdkrljadlgybtvocytpdw4hbnzygxecxehdp7pfj32lxp34a --key bafzbeifyzfm3kosie25s5qthvvcjrr42ivd7doqhwvu5m4ks7uqv4j5lyi\n```\n\nLastly, we could have just copied `.textile/config.yml` to a new directory and used `buck pull` to pull down the existing content.\n\n### Creating a bucket from an existing Cid\n\nSometimes it's useful to create a bucket from a [UnixFS](https://github.com/ipfs/go-unixfs) directory that is already on the IPFS network.\n\nWe can simulate this scenario by adding a local folder to IPFS and then using its root Cid to create a bucket with the `--cid` flag. Here's a local directory.\n\n```\n.\n├── a\n│   ├── bar.txt\n│   ├── foo.txt\n│   └── one\n│       ├── baz.txt\n│       ├── buz.txt\n│       └── two\n│           ├── boo.txt\n│           └── fuz.txt\n├── b\n│   ├── foo.txt\n│   └── one\n│       ├── baz.txt\n│       ├── muz.txt\n│       ├── three\n│       │   └── far.txt\n│       └── two\n│           └── fuz.txt\n└── c\n    ├── one.jpg\n    └── two.jpg\n```\n\nUse the recursvie flag `-r` with `ipfs add`.\n\n```\nipfs add -r .\nadded QmcDkcMJXZsNnExehsE1Yh6SRWucHa9ruVT82gpL83431W mydir/a/bar.txt\nadded QmYiUq2U6euWnKag23wFppG12hon4EBDswdoe4MwrKzDBn mydir/a/foo.txt\nadded QmXrd35ja3kknnmgj5kyDM74jfG8GLJJQGtRpEQpXCLTR3 mydir/a/one/baz.txt\nadded QmSWJvCzotB3CbdxVu8mBvmLqpSuEQgUoJHTFy1azRfwhT mydir/a/one/buz.txt\nadded QmT6h1eaBV74Sh75upE7ugFLkBnmyGr3WsQ8w8yx5NjgPV mydir/a/one/two/boo.txt\nadded QmTdg1b5eWEx4zJtrgvew1inkkZ29fp9mbQ4uHyKurW8Ub mydir/a/one/two/fuz.txt\nadded QmYiQAk1seXrmuQkpGE83AxJyNZDK1RNSaLyp3Z4r1zsrB mydir/b/foo.txt\nadded QmXrd35ja3kknnmgj5kyDM74jfG8GLJJQGtRpEQpXCLTR3 mydir/b/one/baz.txt\nadded QmSWJvCzotB3CbdxVu8mBvmLqpSuEQgUoJHTFy1azRfwhT mydir/b/one/muz.txt\nadded QmYs12A3CGSTHX4QrsvBe2AvLHEThrapXoTFQpyh8AzpFa mydir/b/one/three/far.txt\nadded QmTdg1b5eWEx4zJtrgvew1inkkZ29fp9mbQ4uHyKurW8Ub mydir/b/one/two/fuz.txt\nadded QmaLpwNPwftSQY3w4ZtMfZ8k38D5EgK2bcDuU4UwzREJpi mydir/c/one.jpg\nadded QmYLiWv2WXQd1m8YyHx4dMoj8B3Kuiuu7pCCoYibkqKyVj mydir/c/two.jpg\nadded QmT5YXeCfbMuVjanbHjQhECUQSACJLecfmjRBZHvmu5FDU mydir/a/one/two\nadded QmWh2Wx9Lec4wbEvFbsq4HmYjFmgUFtxNJ8wEVwXjhJ2uk mydir/a/one\nadded QmSujVHvG8Y3Jv21AbMFNQPphjyqNamh6cvdyXSD1jAtSZ mydir/a\nadded QmUGSorWDy2JiKYvQuJzEb4TnYDuDNLcdFyR6NhMwnwdvy mydir/b/one/three\nadded QmWvX7UVexbjXJtxKMyMSgGpPesFQD7teNTqUcDsP2mzW6 mydir/b/one/two\nadded QmPyMD67EgSZS1WpvgudHkxbA5zgjqmse8srPpFb9sVefT mydir/b/one\nadded QmQdAtg5NkwkvLtTbka3eci58UGj3m9AehC2sbksGSbjPZ mydir/b\nadded QmcjtVAF9PQfMKTc57vcvZeBrzww3TLxPcQfUQW7cXXLJL mydir/c\nadded QmcvkGF2t8Z94UqhdtdFRokGoqypbGyKkzRPVF4owmjVrE mydir\n```\n\nAfter adding the entire directory, we see the root Cid is `QmcvkGF2t8Z94UqhdtdFRokGoqypbGyKkzRPVF4owmjVrE`. Let's create the bucket using this Cid.\n\n```\nbuck init --cid QmcvkGF2t8Z94UqhdtdFRokGoqypbGyKkzRPVF4owmjVrE\n```\n\nThe files behind the Cid will be pulled into the new bucket.\n\n```\n+ a/bar.txt: QmcDkcMJXZsNnExehsE1Yh6SRWucHa9ruVT82gpL83431W\n+ a/foo.txt: QmYiUq2U6euWnKag23wFppG12hon4EBDswdoe4MwrKzDBn\n+ a/one/two/fuz.txt: QmTdg1b5eWEx4zJtrgvew1inkkZ29fp9mbQ4uHyKurW8Ub\n+ a/one/baz.txt: QmXrd35ja3kknnmgj5kyDM74jfG8GLJJQGtRpEQpXCLTR3\n+ c/two.jpg: QmYLiWv2WXQd1m8YyHx4dMoj8B3Kuiuu7pCCoYibkqKyVj\n+ b/foo.txt: QmYiQAk1seXrmuQkpGE83AxJyNZDK1RNSaLyp3Z4r1zsrB\n+ a/one/buz.txt: QmSWJvCzotB3CbdxVu8mBvmLqpSuEQgUoJHTFy1azRfwhT\n+ a/one/two/boo.txt: QmT6h1eaBV74Sh75upE7ugFLkBnmyGr3WsQ8w8yx5NjgPV\n+ b/one/muz.txt: QmSWJvCzotB3CbdxVu8mBvmLqpSuEQgUoJHTFy1azRfwhT\n+ b/one/three/far.txt: QmYs12A3CGSTHX4QrsvBe2AvLHEThrapXoTFQpyh8AzpFa\n+ b/one/baz.txt: QmXrd35ja3kknnmgj5kyDM74jfG8GLJJQGtRpEQpXCLTR3\n+ b/one/two/fuz.txt: QmTdg1b5eWEx4zJtrgvew1inkkZ29fp9mbQ4uHyKurW8Ub\n+ c/one.jpg: QmaLpwNPwftSQY3w4ZtMfZ8k38D5EgK2bcDuU4UwzREJpi\n\u003e Your bucket links:\n\u003e http://127.0.0.1:8006/thread/bafk3k3itq2rsybcvhf6wuvumruw3j6cw7ixhrtx4ek45qgvp3e7u2xa/buckets/bafzbeiawo6ghgsqjlorii4wghdl4tzz54x2kiwtcgtaq7b3h5gta2yok2i Thread link\n\u003e http://127.0.0.1:8006/ipns/bafzbeiawo6ghgsqjlorii4wghdl4tzz54x2kiwtcgtaq7b3h5gta2yok2i IPNS link (propagation can be slow)\n\u003e Success! Initialized /path/to/mybucket3 as a new bootstrapped bucket\n```\n\nCurrently, UnixFS in `go-ipfs` uses Cid version 0, which is why we see all these old-style Cids started with `Qm`. Of course, you can also use UnixFS directories that use Cid version 1.\n\nSimilar to initializing a new bucket from an existing Cid, `buck add` allows you to _add_ and/or _merge in_ an existing UnixFS directory to an _existing bucket_. Like adding new files locally, this works by pulling down the UnixFS content from the IPFS network into the local bucket. Sync the changes with `buck push` as normal.\n\nPulling an existing UnixFS directory into a new or existing private bucket is also possible. Just opt-in to encryption during initialization as normal. `buckd` will recursively encrypt (without duplicating) the Cid's IPLD file and directory nodes as they are pulled into the new bucket.\n\n### Exploring bucket contents\n\nUse `buck ls [path]` to explore bucket contents. Omitting `[path]` will list the top-level directory.\n\n```\nbuck ls\n\n  NAME          SIZE     DIR    OBJECTS  CID\n  .textileseed  32       false  n/a      bafkreiezexkrnk7yew6glm6sulhur66bbecc2aeaitf7uz4ymmp442lepu\n  a             3726     true   3        QmSujVHvG8Y3Jv21AbMFNQPphjyqNamh6cvdyXSD1jAtSZ\n  b             3191     true   2        QmQdAtg5NkwkvLtTbka3eci58UGj3m9AehC2sbksGSbjPZ\n  c             1537626  true   2        QmcjtVAF9PQfMKTc57vcvZeBrzww3TLxPcQfUQW7cXXLJL\n```\n\nUse `[path]` to drill into directories, e.g.,\n\n```\nbuck ls a\n\n  NAME     SIZE  DIR    OBJECTS  CID\n  bar.txt  517   false  n/a      QmcDkcMJXZsNnExehsE1Yh6SRWucHa9ruVT82gpL83431W\n  foo.txt  557   false  n/a      QmYiUq2U6euWnKag23wFppG12hon4EBDswdoe4MwrKzDBn\n  one      2502  true   3        QmWh2Wx9Lec4wbEvFbsq4HmYjFmgUFtxNJ8wEVwXjhJ2uk\n```\n\n`buck cat` functions a lot like `ls`, but cats file contents to stdout.\n\n### Resetting bucket contents\n\nSimilar to a `git reset --hard`, you can use `buck pull --hard` to discard local changes that have not been pushed.\n\nContinuing with the bucket above, add, modify, and/or delete some files. `buck status` should show your staged changes.\n\n```\nbuck status\n\u003e modified:  a/bar.txt\n\u003e deleted:   a/one/baz.txt\n\u003e new file:  b/one/three/car.txt\n\u003e deleted:   b/foo.txt\n```\n\nNormally, `buck pull` will move your local changes to temporary `.buckpatch` files, apply the remote / upstream changes, then reapply your local changes. However, the `--hard` flag will prune all local changes, resetting the local bucket contents to match the remote exactly.\n\n```\nbuck pull --hard\n+ a/one/baz.txt: QmXrd35ja3kknnmgj5kyDM74jfG8GLJJQGtRpEQpXCLTR3\n+ b/foo.txt: QmYiQAk1seXrmuQkpGE83AxJyNZDK1RNSaLyp3Z4r1zsrB\n+ a/bar.txt: QmcDkcMJXZsNnExehsE1Yh6SRWucHa9ruVT82gpL83431W\n- b/one/three/car.txt\n\u003e QmTz6HoC18QQqAEtYhfLc4Fse3LPbSCKV8vouvE88MKjFj\n```\n\nNow `buck status` will report `\u003e Everything up-to-date`.\n\nTry `buck pull --help` for more options when pulling the remote.\n\n### Watching a bucket for changes\n\nSo far we've seen how a bucket can change locally, but the remote can also change. This could happen for a couple of reasons:\n\n* Changes are pushed from a different bucket copy against the same `buckd`.\n* Changes are pushed from a different `buckd` at the ThreadDB layer. This is known as a multi-writer scenario. See [Multi-writer buckets](#multi-writer-buckets) for more.\n\nIn either case, it is possible to listen for and apply the remote changes using `buck watch`. This will also watch for local changes and auto-push them to the remote. In this way, multiple copies of the same bucket can be kept in sync.\n\n`watch` will block until it's cancelled with a Ctrl-C.\n\n```\nbuck watch\n\u003e Success! Watching /path/to/mybucket for changes...\n```\n\n`watch` will survive network interruptions, reconnecting when possible.\n\n```\n\u003e Not connected. Trying to connect...\n\u003e Not connected. Trying to connect...\n\u003e Not connected. Trying to connect...\n\u003e Success! Watching /path/to/mybucket for changes...\n```\n\nWhile `watch` is active, file and folders dropped into the bucket will be automatically pushed.\n\n### Protecting a file with a password\n\nPrivate buckets handle encryption entirely within `buckd`, but you can use an additional client-side encryption layer with `buck encrypt` to password protect files. This encryption is also AES-CTR + AES-512 HMAC, which means you can efficiently encrypt large file streams. However, unlike bucket-wide encryption in private buckets, client-side encryption is only available for files, not IPLD directory nodes.\n\nLet's create an encrypted version of the `hello.txt` file.\n\n```\nbuck encrypt hello.txt supersecret \u003e secret.txt\n```\n\n`encrypt` writes to stdout. So, here we redirect the output to a new file called `secret.txt`. [scrypt](https://pkg.go.dev/golang.org/x/crypto/scrypt?tab=doc) is used to derive the AES and HMAC keys from a password. This carries the normal tradeoff: _The encryption is only as good as the password_. Also, as with all client-side encryption, you must also store or otherwise remember the password!\n\n`encrypt` only works on local files. You'll have to use `push` to sync the new file to the remote.\n\n```\nbuck push --yes\n+ secret.txt: bafkreiayymufgaut3wrfbzfdxiacxn64mxijj54g2osyk7qnco54iftovi\n\u003e bafybeidhffwg5ucwktn7iwyvnkhxpz7b2yrh643bo74cjvsbquzpdgpcd4\n```\n\n`decrypt`, on the other hand, works on remote files. So, after pushing `secret.txt`, we can decrypt it (if we can remember the password) and write the plaintext to stdout.\n\n```\nbuck decrypt secret.txt supersecret\nhello world\n```\n\nLooks like it worked!\n\n### Sharing bucket files and folders\n\nBucket contents can be shared with other users using the `buck roles` command. Each file and folder in a bucket maintains a set of public-key based access roles: `None`, `Reader`, `Writer`, and `Admin`. Only the `Admin` role can add and remove files and folders from a shared path. See `buck roles grant --help` for more about each role.\n\nBy default, public buckets have two roles located at the top-level path:\n\n```\nbuck roles ls\n\n  IDENTITY                                                     ROLE\n  *                                                            Reader\n  bbaareibzpb44ahd7oieqevvlqajidd4jajcvx2vdvti6bpw5wkqolwwerm  Admin\n\n\u003e Found 2 access roles\n```\n\nSince access roles are inherited down a bucket path, the single admin role grants the owner full access to all current and future files and folders. The default (`*`) `Read` role indicates that the entire bucket is open to the world. This is merely a reflection of the fact that the underlying UnixFS directory behind public (non-encrypted) buckets are discoverable on the IPFS Network.\n\nPrivate buckets are not open to the world and are created with only the single admin role. However, we can still grant default (`*`) `Read` access to individual files, folders, or the entire bucket posteriori.\n\n```\nbuck roles grant \"*\" myfolder\nUse the arrow keys to navigate: ↓ ↑ → ←\n? Select a role:\n  None\n  ▸ Reader\n  Writer\n  Admin\n```\n\nWe can now see a new role added to `myfolder`.\n\n```\nbuck roles ls myfolder\n\n  IDENTITY  ROLE\n  *         Reader\n\n\u003e Found 1 access roles\n```\n\nSimilarly, grant the `None` role to revoke access.\n\n### Multi-writer buckets\n\nMulti-writer buckets leverage the distributed nature of ThreadDB by allowing multiple identities to write to the same bucket hosted by different Libp2p hosts. Since buckets are ThreadDB collection _instances_, this is no different from normal ThreadDB peer collaboration.\n\n### Deleting a bucket\n\nDeleting a bucket is easy—and permanent! `buck destroy` will delete your local bucket as well as the remote, making it unrecoverable with `buck init --existing`.\n\n### Using the Local Library\n\nThe `local` library powers both the `buck` CLI. Everything possible in `buck`, from bucket diffing, pushing, pulling, watching, archiving, etc., is available to you in existing projects by importing the Local Library.\n\n```\ngo get github.com/textileio/go-buckets/local\n```\n\nVisit the [GoDoc](https://pkg.go.dev/github.com/textileio/go-buckets/local) for a complete list of methods and more usage descriptions.\n\n#### Creating a bucket\n\nCreate a new bucket by constructing a configuration object. Only `Path` is required.\n\n```go\n// Setup the buckets lib\nbuckets := local.NewBuckets(cmd.NewClients(\"api.textile.io:443\", false), local.DefaultConfConfig())\n\n// Create a new bucket with config\nmybuck, err := buckets.NewBucket(context.Background(), local.Config{\n    Path: \"path/to/bucket/folder\"\n})\n\n// Check current status\ndiff, err := mybuck.DiffLocal() // diff contains staged changes\n```\n\n`buckets.NewBucket` will write a local config file and data repo.\n\nSee `local.WithName`, `local.WithStrategy`, `local.WithPrivate`, `local.WithCid`, `local.WithInitEvents` for more options when creating buckets.\n\nTo create a bucket from an existing remote, use its thread ID and instance ID (bucket `key`) in the config.\n\n#### Getting an existing bucket\n\n`GetLocalBucket` returns the bucket at path.\n\n```go\nmybuck, err := buckets.GetLocalBucket(context.Background(), \"path/to/bucket/folder\")\n```\n\n#### Pushing local files\n\n`PushLocal` pushes all staged changes to the remote and returns the new local and remote root Cids. These roots will only be different if the bucket is private (the remote is encrypted).\n\n```go\nnewRoots, err := mybuck.PushLocal()\n```\n\nSee `local.PathOption` for more options when pushing.\n\n#### Pulling remote changes\n\n`PullRemote` pulls all remote changes locally and returns the new root Cids.\n\n```go\nnewRoots, err := mybuck.PullRemote()\n```\n\nSee `local.PathOption` for more options when pulling.\n\n## Developing\n\nThe easiest way to develop against `hubd` or `buckd` is to use the Docker Compose files found in `cmd`. The `-dev` flavored files do not persist repos via Docker Volumes, which may be desirable in some cases.\n\n## Contributing\n\nPull requests and bug reports are very welcome ❤️\n\nThis repository falls under the Textile [Code of Conduct](./CODE_OF_CONDUCT.md).\n\nFeel free to get in touch by:\n-   [Opening an issue](https://github.com/textileio/go-buckets/issues/new)\n-   Joining the [public Slack channel](https://slack.textile.io/)\n-   Sending an email to contact@textile.io\n\n## Changelog\n\nA changelog is published along with each [release](https://github.com/textileio/go-buckets/releases).\n\n## License\n\n[MIT](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftextileio%2Fgo-buckets","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftextileio%2Fgo-buckets","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftextileio%2Fgo-buckets/lists"}