https://github.com/artipie/asto
Abstract Storage for All Artipie Slices
https://github.com/artipie/asto
java java-8 storage
Last synced: 9 months ago
JSON representation
Abstract Storage for All Artipie Slices
- Host: GitHub
- URL: https://github.com/artipie/asto
- Owner: artipie
- License: mit
- Archived: true
- Created: 2019-12-23T09:38:05.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-12-22T13:31:59.000Z (over 2 years ago)
- Last Synced: 2025-08-03T15:51:35.346Z (11 months ago)
- Topics: java, java-8, storage
- Language: Java
- Homepage: https://www.artipie.com
- Size: 1.3 MB
- Stars: 21
- Watchers: 8
- Forks: 14
- Open Issues: 18
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.header
Awesome Lists containing this project
README
[](http://t.me/artipie)
[](https://www.elegantobjects.org)
[](https://www.jetbrains.com/idea/)
[](http://www.javadoc.io/doc/com.artipie/asto-core)
[](https://github.com/artipie/asto/blob/master/LICENSE.txt)
[](https://codecov.io/gh/artipie/asto)
[](https://hitsofcode.com/view/github/artipie/asto)
[](https://maven-badges.herokuapp.com/maven-central/com.artipie/asto-core)
[](http://www.0pdd.com/p?name=artipie/asto)
Asto stands for Abstract Storage, an abstraction over physical data storage system.
The main entity of the library is an interface `com.artipie.asto.Storage`, a contract
which requires to implement the following functionalities:
* put/get/delete operations
* transaction support
* list files in a directory
* check if a file/directory exists
* provide file metadata (size, checksums, type, etc.)
Dictionary used for ASTO:
- `Storage` - key-value based storage
- `Key` - storage keys, could be converted to strings
- `Content` - storage data, reactive publisher with optional size attribute
- `SubStorage` - isolated storage based on origin storage
The list of back-ends supported:
- FileStorage - file-system based storage, uses paths as keys, stores content in files
- S3Storage - uses S3 compatible HTTP web-server as storage, uses keys as names and blobs for content
- EtcdStorage - uses ETCD cluster as storage back-end
- InMemoryStorage - storage uses `HashMap` to store data
- RedisStorage - storage based on [Redisson](https://github.com/redisson/redisson)
This is the dependency you need:
```xml
com.artipie
asto-core
[...]
```
The following dependency allows using RedisStorage:
```xml
com.artipie
asto-redis
[...]
```
Read the [Javadoc](http://www.javadoc.io/doc/com.artipie/asto-core) for more technical details.
If you have any question or suggestions, do not hesitate to [create an issue](https://github.com/artipie/asto/issues/new)
or contact us in [Telegram](https://t.me/artipie).
Artipie [roadmap](https://github.com/orgs/artipie/projects/3).
# Usage
The main entities here are:
- `Storage` interface provides API for key-value storage
- `Key` represents storage key
- `Content` represents storage binary value
[Storage](https://www.javadoc.io/doc/com.artipie/asto/latest/com/artipie/asto/Storage.html),
[Key](https://www.javadoc.io/doc/com.artipie/asto/latest/com/artipie/asto/Key.html) and other entities are
documented in [javadoc](https://www.javadoc.io/doc/com.artipie/asto/latest/index.html).
Here is en example of how to create `FileStorage`, save and then read some data:
```java
final Storage asto = new FileStorage(Path.of("/usr/local/example"));
final Key key = new Key.From("hello.txt");
asto.save(
key,
new Content.From("Hello world!".getBytes(StandardCharsets.UTF_8))
).thenCompose(
ignored -> asto.value(key)
).thenCompose(
val -> new PublisherAs(val).asciiString()
).thenAccept(
System.out::println
).join();
```
In the example we created local text file `/usr/local/example/hello.txt` containing string "Hello world!",
then read and print it into console. Used classes:
- `Key.From` is implementation of the `Key` interface, keys are strings, separated by `/`
- `Content.From` implements `Content` interface, allows to create `Content` instances from
byte arrays or [publisher](https://www.reactive-streams.org/reactive-streams-1.0.4-javadoc/org/reactivestreams/Publisher.html) of ByteBuffer's
- `PublisherAs` class allows to fully read `Content` into memory as byte arrays
Note, that `Storage` is asynchronous and always returns `CompletableFutures` as a result, use
future chains (`thenAccept()`, `thenCompose()` etc.) and call blocking methods `get()` or `join()`
when necessary.
Other storage implementations (`S3Storage`, `InMemoryStorage`, `RedisStorage`) can be used in the same way, only
constructors differ, here is an example of how to create `S3Storage` instance:
```java
final Storage asto = new S3Storage(
S3AsyncClient.builder().credentialsProvider(
StaticCredentialsProvider.create(
AwsBasicCredentials.create("accessKeyId", "secretAccessKey")
)
).build(),
"bucketName"
);
```
To get more details about `S3AsyncClient` builder, check
[Java S3 client docs](https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/services/s3/S3AsyncClient.html).
## How to contribute
Please read [contributing rules](https://github.com/artipie/artipie/blob/master/CONTRIBUTING.md).
Fork repository, make changes, send us a pull request. We will review
your changes and apply them to the `master` branch shortly, provided
they don't violate our quality standards. To avoid frustration, before
sending us your pull request please run full Maven build:
```
$ mvn clean install -Pqulice
```
To avoid build errors use Maven 3.2+.