Skip to content

Commit 903c1d3

Browse files
committed
add AWSS3 as weakdep
1 parent dd5d23b commit 903c1d3

File tree

4 files changed

+83
-3
lines changed

4 files changed

+83
-3
lines changed

Project.toml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
name = "Onda"
22
uuid = "e853f5be-6863-11e9-128d-476edb89bfb5"
33
authors = ["Beacon Biosignals, Inc."]
4-
version = "0.15.2"
5-
4+
version = "0.15.3"
65

76
[deps]
87
Arrow = "69666777-d1a9-59fb-9406-91d4454c9d45"
@@ -17,6 +16,12 @@ TimeSpans = "bb34ddd2-327f-4c4a-bfb0-c98fc494ece1"
1716
TranscodingStreams = "3bb67fe8-82b1-5028-8e26-92a6c54297fa"
1817
UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
1918

19+
[weakdeps]
20+
AWSS3 = "1c724243-ef5b-51ab-93f4-b0a88ac62a95"
21+
22+
[extensions]
23+
OndaAWSS3Ext = "AWSS3"
24+
2025
[compat]
2126
Arrow = "1.6.2, 2"
2227
CodecZstd = "0.6, 0.7"
@@ -30,9 +35,11 @@ TranscodingStreams = "0.9"
3035
julia = "1.6"
3136

3237
[extras]
38+
AWSS3 = "1c724243-ef5b-51ab-93f4-b0a88ac62a95"
3339
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
3440
FLAC_jll = "1d38b3a6-207b-531b-80e8-c83f48dafa73"
41+
Minio = "4281f0d9-7ae0-406e-9172-b7277c1efa20"
3542
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
3643

3744
[targets]
38-
test = ["FLAC_jll", "DataFrames", "Test"]
45+
test = ["AWSS3", "FLAC_jll", "DataFrames", "Minio", "Test"]

ext/OndaAWSS3Ext.jl

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
module OndaAWSS3Ext
2+
3+
using AWSS3: S3Path
4+
using Onda: Onda
5+
6+
"""
7+
Onda.read_byte_range(path::S3Path, byte_offset, byte_count)
8+
9+
Implement method needed for Onda to read a byte range from an S3 path. Uses
10+
`AWSS3.s3_get` under the hood.
11+
12+
"""
13+
function Onda.read_byte_range(path::S3Path, byte_offset, byte_count)
14+
# s3_get byte_range is 1-indexed, so we need to add one
15+
byte_range = range(byte_offset + 1; length=byte_count)
16+
return read(path; byte_range)
17+
end
18+
19+
# avoid method ambiguity
20+
function Onda.read_byte_range(path::S3Path, ::Missing, ::Missing)
21+
return read(path)
22+
end
23+
24+
end # module

test/awss3.jl

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
function minio_server(body, dirs=[mktempdir()]; address="localhost:9005")
2+
server = Minio.Server(dirs; address)
3+
4+
try
5+
run(server; wait=false)
6+
sleep(0.5) # give the server just a bit of time, though it is amazingly fast to start
7+
8+
config = MinioConfig(
9+
"http://$address"; username="minioadmin", password="minioadmin"
10+
)
11+
body(config)
12+
finally
13+
# Make sure we kill the server even if a test failed.
14+
kill(server)
15+
end
16+
end
17+
18+
@testset "AWSS3 usage" begin
19+
minio_server() do config
20+
s3_create_bucket(config, "test-bucket")
21+
22+
file_format = "lpcm.zst"
23+
file_path = S3Path("s3://test-bucket/prefix/samples.$(file_format)"; config)
24+
recording_uuid = uuid4()
25+
start = Second(0)
26+
27+
info = SamplesInfoV2(sensor_type="eeg",
28+
channels=["a", "b"],
29+
sample_unit="unit",
30+
sample_resolution_in_unit=1.0,
31+
sample_offset_in_unit=0.0,
32+
sample_type=Int16,
33+
sample_rate=100.0)
34+
samples = Samples(zeros(sample_type(info), 2, 300), info, true)
35+
36+
signal = Onda.store(file_path, file_format, samples, recording_uuid, start)
37+
@test signal.file_path isa S3Path
38+
39+
loaded_samples = Onda.load(signal; encoded=true)
40+
@test samples == loaded_samples
41+
42+
# Load subspan to exercise method
43+
span = TimeSpan(0, Second(1))
44+
loaded_span = Onda.load(signal, span; encoded=true)
45+
@test loaded_samples[:, span] == loaded_span
46+
end
47+
end

test/runtests.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Compat: @compat
22
using Test, UUIDs, Dates, Onda, Legolas, Arrow, Tables, TimeSpans, DataFrames, Random
33
using Tables: rowmerge
4+
using AWSS3, Minio # for testing AWSS3 package extension
45

56
function has_rows(a, b)
67
for name in propertynames(b)
@@ -17,5 +18,6 @@ include("signals.jl")
1718
include("serialization.jl")
1819
include("samples.jl")
1920
include("deprecations.jl")
21+
include("awss3.jl")
2022
include(joinpath(dirname(@__DIR__), "examples", "flac.jl"))
2123
include(joinpath(dirname(@__DIR__), "examples", "tour.jl"))

0 commit comments

Comments
 (0)