Reading and Writing Files

Reading from and writing to files is straight forward in DataFS. In this section we’ll cover the command-line implementation of this. The python implementation is also available.

We’ll assume you have your api configured with a manager and an authority. Check the configure documentation for more information on how to set up DataFS.

Listing Archives

If I want to first check to see if I have any archives I can use the filter command. Here we see we don’t currently have any archives

$ datafs filter

So let’s create an archive so we have something to work with.

$ datafs create my_archive
created versioned archive <DataArchive local://my_archive>

Now when we list we see our archive. Great!

$ datafs filter

Writing to Archives

This time we will simply demonstrate how you can

$ datafs update my_archive \
>   --string 'barba crescit caput nescit' # doctest: +NORMALIZE_WHITESPACE
uploaded data to <DataArchive local://my_archive>. new version 0.0.1


Reading from Archives

$ datafs download my_archive 'my_archive.txt'
downloaded v0.0.1 to my_archive.txt

Now let’s read this to make sure we got what we want

$ cat my_archive.txt
barba crescit caput nescit

Writing to Archives with Filepaths

Let’s say we made some major edits to my_archive locally and we want to update them in the manager and at our authority. We can update the same as before but this time we’ll add the filepath that points to our file.

$ datafs update my_archive my_archive.txt # doctest: +NORMALIZE_WHITESPACE
uploaded data to <DataArchive local://my_archive>. version bumped 0.0.1 -->

And now to read this file, let’s download to a different spot and read from there.

$ datafs download my_archive my_archive_placeholder.txt
downloaded v0.0.2 to my_archive_placeholder.txt

$ cat my_archive_placeholder.txt # doctest: +NORMALIZE_WHITESPACE
barba crescit caput nescit
luctuat nec mergitur

We can see that our updates have been added and that they are reflected in a new version number.