There are multiple ways to fetch data from a storage provider. This page covers some of the most popular methods.
Lassie is a simple retrieval client for IPFS and Filecoin. It finds and fetches your data over the best retrieval protocols available. Lassie makes Filecoin retrieval easy. While Lassie is powerful, the core functionality is expressed in a single CLI command:
lassie fetch <CID>
Lassie also provides an HTTP interface for retrieving IPLD data from IPFS and Filecoin peers. Developers can use this interface directly in their applications to retrieve the data.
Lassie fetches content in content-addressed archive (CAR) form, so in most cases, you will need additional tooling to deal with CAR files. Lassie can also be used as a library to fetch data from Filecoin from within your application. Due to the diversity of data transport protocols in the IPFS ecosystem, Lassie is able to use the Graphsync or Bitswap protocols, depending on how the requested data is available to be fetched. One prominent use case of Lassie as a library is the Saturn Network. Saturn nodes fetch content from Filecoin and IPFS through Lassie in order to serve retrievals.
go install github.com/filecoin-project/lassie/cmd/lassie@latest
go install github.com/ipld/go-car/cmd/car@latest
You now have everything you need to retrieve a file with Lassie and extract the contents with
To retrieve data from Filecoin using Lassie, all you need is the CID of the content you want to download.
The video below demonstrates how Lassie can be used to render content directly from Filecoin and IPFS.
go-carcan work together to retrieve and extract data from Filecoin. All you need is the CID of the content to download.
lassie fetch -o - <CID> | car extract
This command uses a
|to chain two commands together. This will work on Linux or macOS. Windows users may need to use PowerShell to use this form. Alternatively, you can use the commands separately, as explained later on this page.
An example of fetching and extracting a single file, identified by its CID:
lassie fetch -o - bafykbzaceatihez66rzmzuvfx5nqqik73hlphem3dvagmixmay3arvqd66ng6 | car extract - > lidar-data.tar
Basic progress information, similar to the output shown below, is displayed:
Fetched [bafykbzaceatihez66rzmzuvfx5nqqik73hlphem3dvagmixmay3arvqd66ng6] from [12D3KooWPNbkEgjdBNeaCGpsgCrPRETe4uBZf1ShFXStobdN18ys]:
Bytes: 143 MiB
extracted 1 file(s)
The resulting file is a tar archive:
# total 143M
# -rw-rw-r-- 1 user user 143M Feb 16 11:21 lidar-data.tar
Lassie CLI usage
Lassie's usage for retrieving data is as follows:
lassie fetch -p -o <OUTFILE_FILE_NAME> <CID>/path/to/content
-pis an optional flag that tells Lassie that you would like to see detailed progress information as it fetches your data.For example:
- Fetching bafykbzaceatihez66rzmzuvfx5nqqik73hlphem3dvagmixmay3arvqd66ng6Querying indexer for bafykbzaceatihez66rzmzuvfx5nqqik73hlphem3dvagmixmay3arvqd66ng6...Found 4 storage providers candidates from the indexer, querying all of them:12D3KooWPNbkEgjdBNeaCGpsgCrPRETe4uBZf1ShFXStobdN18ys12D3KooWNHwmwNRkMEP6VqDCpjSZkqripoJgN7eWruvXXqC2kG9f12D3KooWKGCcFVSAUXxe7YP62wiwsBvpCmMomnNauJCA67XbmHYj12D3KooWLDf6KCzeMv16qPRaJsTLKJ5fR523h65iaYSRNfrQy7eUQuerying [12D3KooWLDf6KCzeMv16qPRaJsTLKJ5fR523h65iaYSRNfrQy7eU] (started)...Querying [12D3KooWKGCcFVSAUXxe7YP62wiwsBvpCmMomnNauJCA67XbmHYj] (started)......
-ois an optional flag that tells Lassie where to write the output to. If you don’t specify a file, it will append
.carto your CID and use that as the output file name.
If you specify
-p, the output will be written to
stdoutso it can be piped to another command, such as
go-car, or redirected to a file.
<CID>/path/to/contentis the CID of the content you want to retrieve and an optional path to a specific file within that content. Example:
- lassie fetch -o - bafybeiaysi4s6lnjev27ln5icwm6tueaw2vdykrtjkwiphwekaywqhcjze/wiki/Cryptographic_hash_function | car extract - | less
A CID is always necessary, and if you don’t specify a path, Lassie will attempt to download the entire content. If you specify a path, Lassie will only download that specific file or, if it is a directory, the entire directory and its contents.
go-car CLI usage
car extractcommand can be used to extract files and directories from a CAR:
car extract -f <INPUT_FILE>[/path/to/file/or/directory] [<OUTPUT_DIR>]
-fis an optional flag that tells
go-carwhere to read the input from. If omitted, it will read from
stdin, as in our example above where we piped
lassie fetch -o -output to
/path/to/file/or/directoryis an optional path to a specific file or directory within the CAR. If omitted, it will attempt to extract the entire CAR.
<OUTPUT_DIR>is an optional argument that tells
go-carwhere to write the output to. If omitted, it will be written to the current directory.
If you supply
-p, as in the above example, it will attempt to extract the content directly to
stdout. This will only work if we are extracting a single file.
In the example above, where we fetched a file named
>operator was used to redirect the output of
car extractto a named file. This is because the content we fetched was raw file data that did not have a name encoded. In this case, if we didn’t use
go-carwould write to a file named
unknown. In this instance,
go-carwas used to reconstitute the file from the raw blocks contained within Lassie’s CAR output.
go-carhas other useful commands. The first is
car ls, which can be used to list the contents of a CAR. The second is
car inspect, which can be used to inspect the contents of the CAR and optionally verify the integrity of a CAR.
And there we have it! Downloading and managing data from Filecoin is super simple when you use Lassie and Go-car!
The Lassie HTTP daemon is an HTTP interface for retrieving IPLD data from IPFS and Filecoin peers. It fetches content from peers known to have it and provides the resulting data in CAR format.
GETquery against a Lassie HTTP daemon allows retrieval from peers that have the content identified by the given root CID, streaming the DAG in the response in CAR (v1) format. You can read more about the HTTP request and response to the daemon in Lassie’s HTTP spec. Lassie’s HTTP interface can be a very powerful tool for web applications that require fetching data from Filecoin and IPFS.