Skip to content

Commit

Permalink
Reformatting.
Browse files Browse the repository at this point in the history
  • Loading branch information
interkosmos committed Apr 3, 2024
1 parent d1087b0 commit 6965e39
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 24 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,15 @@ program main
character(len=:), allocatable :: dst1, dst2, src
integer(kind=c_size_t) :: dst_len, src_len, stat
src = repeat('Hello, there! ', 32)
src = repeat('Hello, there! ', 32)
src_len = len(src, kind=c_size_t)
dst_len = zstd_compress_bound(src_len)
allocate (character(len=dst_len) :: dst1)
allocate (character(len=src_len) :: dst2)
stat = zstd_compress(dst1, dst_len, src, src_len, zstd_default_c_level())
stat = zstd_compress(dst1, dst_len, src, src_len, zstd_default_c_level())
dst_len = stat
if (zstd_is_error(stat)) then
Expand Down
44 changes: 22 additions & 22 deletions test/test_zstd.f90
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,27 @@ program main
if (.not. tests(i)) error stop
end do
contains
integer(kind=c_size_t) function test_read(chunk, pos, to_read, src) result(nbytes)
!! Reads chunk from source `src` and returns chunk length.
character(len=*), intent(inout) :: chunk !! Output chunk.
integer(kind=c_size_t), intent(inout) :: pos !! Current cursor position.
integer(kind=c_size_t), intent(in) :: to_read !! Max. bytes to read.
character(len=*), intent(inout) :: src !! Source to read from.

integer :: pos2

nbytes = 0
if (to_read == 0) return

pos = pos + 1
if (pos > len(src)) return

pos2 = min(pos + to_read, len(src, kind=c_size_t))
chunk = src(pos:pos2)
nbytes = abs(pos2 - pos) + 1
pos = pos2
end function test_read

logical function test_simple() result(success)
!! Simple API.
character(len=:), allocatable :: dst1, dst2, src
Expand Down Expand Up @@ -90,8 +111,8 @@ logical function test_simple_multi() result(success)
allocate (character(len=dst_len) :: dst1)
allocate (character(len=src_len) :: dst2)

level = zstd_default_c_level()
c_ctx = zstd_create_c_ctx()
level = zstd_default_c_level()
stat = zstd_compress_c_ctx(c_ctx, dst1, dst_len, src, src_len, level)
stat2 = zstd_free_c_ctx(c_ctx)

Expand Down Expand Up @@ -122,27 +143,6 @@ logical function test_simple_multi() result(success)
success = .true.
end function test_simple_multi

integer(kind=c_size_t) function test_read(chunk, pos, to_read, src) result(nbytes)
!! Reads chunks from source `src` and returns chunk length.
character(len=*), intent(inout) :: chunk !! Output chunk.
integer(kind=c_size_t), intent(inout) :: pos !! Current cursor position.
integer(kind=c_size_t), intent(in) :: to_read !! Max. bytes to read.
character(len=*), intent(inout) :: src !! Source to read from.

integer :: pos2

nbytes = 0
if (to_read == 0) return

pos = pos + 1
if (pos > len(src)) return

pos2 = min(pos + to_read, len(src, kind=c_size_t))
chunk = src(pos:pos2)
nbytes = abs(pos2 - pos) + 1
pos = pos2
end function test_read

logical function test_stream() result(success)
!! Streaming API.
character(len=:), allocatable :: dst, src1, src2
Expand Down

0 comments on commit 6965e39

Please sign in to comment.