ByteShelfClient 3.0.0
See the version list below for details.
dotnet add package ByteShelfClient --version 3.0.0
NuGet\Install-Package ByteShelfClient -Version 3.0.0
<PackageReference Include="ByteShelfClient" Version="3.0.0" />
<PackageVersion Include="ByteShelfClient" Version="3.0.0" />
<PackageReference Include="ByteShelfClient" />
paket add ByteShelfClient --version 3.0.0
#r "nuget: ByteShelfClient, 3.0.0"
#:package ByteShelfClient@3.0.0
#addin nuget:?package=ByteShelfClient&version=3.0.0
#tool nuget:?package=ByteShelfClient&version=3.0.0
ByteShelfClient
The client for ByteShelf, a self-hosted file store. One interface over a server's shelves, files and users, an HTTP implementation, and an in-memory one so an app's tests need no running server. Targets net8.0 and is AOT-compatible.
Use
HttpClient http = new HttpClient { BaseAddress = new Uri("https://files.example.com/") };
// A program uses the shelves an admin gave its key.
IByteShelfClient client = new ByteShelfHttpClient(http, new ShelfKeyCredentials(secret));
IShelfClient receipts = client.Shelf("receipts");
// Typed application/pdf by its extension; UploadOptions.ContentType says otherwise.
ShelfFile stored = await receipts.UploadAsync("/2026/march.pdf", fileStream);
await using Stream content = await receipts.OpenReadAsync(stored.Id);
A person signs in instead, and the session renews itself:
using UserSession session = await UserSession.SignInAsync(http, email, password);
session.Renewed += (_, _) => Save(session.Tokens); // to resume later with UserSession.Resume(http, saved)
IByteShelfClient client = new ByteShelfHttpClient(http, session);
// ...
await session.SignOutAsync(); // ends it on the server; disposing alone leaves it resumable
IByteShelfClient lists and creates shelves and, with a UserSession, the signed-in user and
(for admins) the other users; a shelf key cannot reach users. Admins also drive replication through
it: GetReplicationAsync (the replicas and how far behind each is, or the primary followed),
CreatePairingCodeAsync, FollowPrimaryAsync, RemoveReplicaAsync and PromoteAsync. IShelfClient works on one shelf:
list a directory or its whole tree, search, find duplicates (FindDuplicatesAsync), read what the
server read from a file's contents (GetFileMetadataAsync), upload, open (part of a file with
OpenReadRangeAsync), describe (many files in
one request with SetDescriptionsAsync), share by a link, make an upload
link, encrypt directories and swap a file's contents in place (SwapContentAsync), create
directories, move (many entries in one request with MoveAsync; a batch applies each item on its
own, in order, and answers each one's result), delete, the trash (ListDeletionAsync and OpenDeletedReadAsync read what a
deletion took without restoring it, on a replica too; the listing also says what the deletion took
and the encrypted folder its files were stored in), and for admins the shelf's settings, grants
and keys. A key may work on several shelves: a shelf's GetKeysAsync lists each key with all its
shelves (ShelfKeyInfo.Grants), SetKeyGrantAsync gives an existing key the shelf or changes its
access there, and RemoveKeyGrantAsync takes the shelf from it, deleting a key with its last shelf.
IByteShelfClient.GetKeyGrantsAsync lists a key's shelves and DeleteKeyAsync deletes it from all.
ByteShelfClient.Encryption encrypts and decrypts with a password, on the client only. Files and
directories are named by path or by id; both convert to an EntryReference.
Uploads
The server needs a file's size before it accepts any bytes. A stream that can seek is sent from its
position to its end; any other stream is first copied to a temporary file. Files up to
ByteShelfHttpClientOptions.SingleRequestMaxBytes (32 MiB) go in one request, larger ones as a
resumable upload in chunks of ChunkBytes (8 MiB). A file with a description always goes as a
resumable upload, since a single request has no body but the contents to carry it. A chunk
interrupted on the way (the connection broke, the HttpClient's timeout ran out, the server failed
with a 5xx, or it holds a different count than the chunk assumed) is sent on from the offset the
server reports, up to three times in a row. Any other failure, or a cancellation, aborts the
upload, so its reservation against the quota is released at once; the abort gets 10 seconds, and
the failure it follows is the one thrown. HttpClient's default timeout of 100 seconds applies to
each request; a program that sends large chunks over a slow line can raise it.
Errors
A shelf name, path, content type, description, search, tree query or link lifetime the rules in
ByteShelfCommon refuse throws ArgumentException before anything is sent. Anything the server refuses throws
ByteShelfException, whose Code is one of ErrorCodes: not_found, conflict,
permission_denied, quota_exceeded, range_not_satisfiable and so on. Two codes come from the
client rather than the server: a ranged read refuses a file whose contents changed with
content_changed, one of ErrorCodes, and a successful answer that is not ByteShelf's (its body,
or a ranged read's headers) throws ByteShelfException.InvalidResponse (invalid_response). A
failed answer without a code in its body takes its code from its status. IsAccessRefused (unauthenticated,
invalid_credentials or permission_denied: the server refused who is asking, or a password or key
they gave, and the same credentials get the same answer), IsNotFound and IsInvalidResponse sort
the codes a program usually acts on. A request that never reached the server throws what HttpClient throws.
Sessions
A UserSession belongs to the server its HttpClient points at. It renews its access token a
minute before it runs out, and once more if the server challenges it. A refresh token works once,
so renewals run one at a time, a renewal already sent finishes even when the request that started
it is cancelled, and Renewed reports each new token. A renewal the server refuses throws its
error: unauthenticated when the session has ended (sign in again), anything else leaves the
session as it was. A streamed upload cannot be sent twice, so it relies on the renewal ahead of
time. Dispose a session when done with it; the HttpClient stays the caller's.
UserSession.Resume(http, tokens) picks up kept Tokens, using the access token while it works.
Processes that share one session open it with UserSession.OpenSharedAsync(http, store) instead:
the ISharedSessionStore is locked for every renewal, which first takes up tokens another process
renewed to and is then saved there, so no two renew with the same refresh token. Signing a shared
session out also happens with the store locked, with the tokens it keeps then, and clears it. The
byteshelf CLI keeps its session that way, in its config file. Once signed out, a session's
requests fail with unauthenticated without being sent.
Downloads
OpenReadAsync hashes the bytes as they are read, and reading to the end throws IOException if
they do not match the file's SHA-256, so a file read whole is the file that was stored.
OpenReadRangeAsync reads part of a file, to seek in a video or answer a browser's Range
request: the bytes from an offset, for a length or to the end, answered as a ShelfFileRange with
the range's Offset and Length, the file's TotalLength and the Sha256 of the contents it came
from. Dispose the range to dispose its stream. A range running past the end is cut at the end; one
starting at or past the end is refused with range_not_satisfiable, except offset 0 with no length,
which answers an empty file as an empty range. Give it the Sha256 read earlier and a file whose
contents have changed since is refused with content_changed rather than answering bytes of other
contents. Part of a file cannot be checked against its SHA-256, so only a range that turns out to be
the whole file is checked. An encrypted file's range is over its stored age bytes, as
OpenReadAsync reads them.
Links
CreateDownloadLinkAsync makes a link to one file that anyone holding it can open without signing
in, for a day unless a lifetime in whole minutes up to 7 days is given, or until it is revoked. Making one is a read, so any
key may. A server with a public URL configured answers the link on it, and the HTTP client keeps it
as it is. Otherwise the server answers a path from its root, which the HTTP client makes absolute
against the HttpClient's base address, or against ByteShelfHttpClientOptions.LinkBaseAddress for
a client that reaches the server at another address than the people the links are for. The in-memory client's links name the file under the reserved
byteshelf.invalid domain, which nothing serves.
CreateUploadLinkAsync makes a link that stores one file at a path when anyone holding it PUTs the
contents with a Content-Length (curl -T file '<link>'), for 15 minutes unless UploadLinkOptions
give a lifetime up to 24 hours, with an optional description and Overwrite. Making one is a store,
so a read key cannot, and one with Overwrite needs write access, so an add-only key cannot either.
The link acts with the client's access, checked again when it is used. Its
URL is made absolute as a download link's is.
Both kinds of link read or store with the access of whoever made them, checked again on every use,
and each answers its Id. GetLinksAsync lists the shelf's links that have not run out, without
their URLs: those this client made, or every one when it may write on the shelf. RevokeLinkAsync
ends one by its id, under the same rule, so no request made with it from then on is served; a replica keeps and revokes its own links. A link
meant to be read once is one with a short lifetime, revoked after it was read. The in-memory client
keeps its links per shelf and lists every one, as it acts as an admin.
Encryption
ByteShelfClient.Encryption encrypts with a password as every ByteShelf client does: an age file
(c2sp.org/age) with a scrypt recipient, which age -d opens too. AgeEncryption encrypts and
decrypts streams; it follows the specification, passes its official test vectors, reads what typage
(age in JavaScript, which the web UI depends on) writes and the other way round, and needs the platform's ChaCha20-Poly1305
(IsSupported). New files are encrypted at work factor 18 (DefaultWorkFactor, age's default), and
a file is decrypted up to 22 (MaxWorkFactor, age's cap), which takes 4 GiB of memory; past it the
file is refused. A failed decryption throws AgeException, whose Failure is NoMatch for a wrong
password (or a file not encrypted with one), Header or Payload for a file that is no age file or
is damaged. IsOpenedByAsync tells whether a password opens a file from its header alone. Store an
encrypted file with UploadOptions.Encrypted. A directory is encrypted with EncryptDirectoryAsync
and a check from FolderPassword.CreateCheckAsync; from then on every file stored under it must be
encrypted with its password, which FolderPassword.MatchesAsync tells against the check that
GetEncryptionAsync or a listing's EncryptedBy answers. Files already
there stay as they are until the client encrypts them in place with SwapContentAsync, which takes
the file's record as it was read and stores the encrypted (or decrypted) contents in its place: the
file keeps its id, and its old contents are gone at once, from replicas too, never to the trash.
A file that changed since it was read is refused with a conflict. RemoveDirectoryEncryptionAsync
ends the rule and leaves the files encrypted. The server keeps the rule
(Storage), and so does the
in-memory client, as far as either can see it: a file stored under the directory must be sent as
encrypted and start as an age file. Neither ever sees the password, so the client that stores the
file is the one that checks it with MatchesAsync. Neither kind of link reaches an encrypted file: making a download link to one, or
an upload link under an encrypted directory or over an encrypted file, throws a conflict.
In tests
InMemoryByteShelfClient keeps everything in memory and follows the server's rules for paths,
names, conflicts, quotas, the trash and users. It acts as a signed-in admin and does not model
access, so nothing is refused for lack of permission. As over HTTP, a refusal or a cancellation
comes through the returned task; only an argument the rules refuse may throw from the call itself.
The admin is CurrentUser; pass email and
password to choose who it is (a test of ChangePasswordAsync needs the password), a
TimeProvider to control timestamps and when the trash is purged, and restoreWindow to change
the 30 days.
Replication is modelled by its rules and state only: an in-memory client can follow another in the same process with its pairing code, after which it refuses writes until promoted, but a follower copies no data, and it is never behind.
File metadata (GetFileMetadataAsync: when a photo was taken, a PDF's title and so on) is read only
by the server, with libraries this package does not carry. In memory every file's metadata is
FileMetadata.None, a search criterion about it (TakenFrom, HasGps, durations, page counts)
matches no file, and search text matches no title or camera.
InMemoryByteShelfClient client = new InMemoryByteShelfClient(email: "me@example.com", password: "a-long-password");
await client.CreateShelfAsync("receipts");
await client.Shelf("receipts").SetGrantAsync(client.CurrentUser.Id, ShelfAccessPermission.Read);
The server's test suite runs the same contract tests against both clients.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- ByteShelfCommon (>= 3.0.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on ByteShelfClient:
| Package | Downloads |
|---|---|
|
EasyReasy.ByteShelfProvider
Enables resources from ByteShelf for EasyReasy |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 4.0.1 | 45 | 11/26/2026 |
| 4.0.0 | 63 | 11/25/2026 |
| 3.1.0 | 73 | 11/20/2026 |
| 3.0.0 | 73 | 11/20/2026 |
| 2.2.0 | 171 | 11/20/2026 |
| 2.1.0 | 100 | 11/19/2026 |
| 2.0.0 | 134 | 11/15/2026 |
| 1.3.0 | 557 | 10/12/2025 |
| 1.2.2 | 470 | 7/14/2025 |
| 1.2.1 | 247 | 7/13/2025 |
| 1.2.0 | 250 | 7/13/2025 |
| 1.1.2 | 223 | 7/12/2025 |
| 1.1.1 | 224 | 7/11/2025 |
| 1.1.0 | 252 | 7/3/2025 |
| 1.0.0 | 248 | 6/18/2025 |
Breaking: a shelf key may work on several shelves, as ByteShelfCommon 3.0.0's ShelfKeyInfo.Grants lists. IShelfClient.DeleteKeyAsync is replaced by RemoveKeyGrantAsync, which takes the shelf from a key and deletes the key only when that was its last shelf; IShelfClient.SetKeyGrantAsync gives an existing key the shelf or changes its access there; IByteShelfClient.GetKeyGrantsAsync lists a key's shelves and IByteShelfClient.DeleteKeyAsync deletes a key from every shelf. All of these in the HTTP client and the in-memory one. CreateKeyAsync and SetKeyGrantAsync throw ArgumentException for a permission that is none of the values, before anything is sent. Needs a ByteShelf server whose keys hold grants (its migration v0014). IShelfClient and IByteShelfClient change members, so an implementation outside ByteShelfClient must follow. See https://github.com/AdamTovatt/byte-shelf/blob/client-v3.0.0/ByteShelfClient/README.md