• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

camatcode / basenji / 594b515fe95c2d0848feedc055b9a66fb92a59c3

06 Jul 2025 05:05PM UTC coverage: 64.232% (+4.7%) from 59.566%
594b515fe95c2d0848feedc055b9a66fb92a59c3

push

github

web-flow
Merge pull request #24 from camatcode/work/json_api_collections

feat(collections): json_api

43 of 49 new or added lines in 10 files covered. (87.76%)

1 existing line in 1 file now uncovered.

343 of 534 relevant lines covered (64.23%)

385.28 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

88.89
/lib/basenji/reader/cbz_reader.ex
1
defmodule Basenji.Reader.CBZReader do
2
  @moduledoc false
3
  import Basenji.Reader
4

5
  def format, do: :cbz
6✔
6

7
  def get_magic_numbers, do: [%{offset: 0, magic: [0x50, 0x4B, 0x03, 0x04]}]
2,379✔
8

9
  # opts[:close] - will close the stream after reading
10
  def get_entries(cbz_file_path, opts \\ []) when is_bitstring(cbz_file_path) do
11
    with {:ok, unzip} <- open(cbz_file_path) do
625✔
12
      file_entries =
624✔
13
        Unzip.list_entries(unzip)
14
        |> sort_file_names()
15
        |> reject_macos_preview()
16

17
      if opts[:close] do
624✔
18
        close(unzip)
2✔
19
        {:ok, %{entries: file_entries, file: nil}}
20
      else
21
        {:ok, %{entries: file_entries, file: unzip}}
22
      end
23
    end
24
  end
25

26
  def get_entry_stream!(%Unzip{} = unzip, %Unzip.Entry{file_name: file_name}) do
UNCOV
27
    get_entry_stream!(unzip, file_name, [])
×
28
  end
29

30
  def get_entry_stream!(%Unzip{} = unzip, file_name) do
31
    get_entry_stream!(unzip, file_name, [])
×
32
  end
33

34
  # opts[:chunk_size] - Chunks are read from the source of the size specified by chunk_size.
35
  #         This is not the size of the chunk returned by file_stream! since the chunk size varies after decompressing
36
  #         the stream. Useful when reading from the source is expensive and you want optimize by increasing the chunk size.
37
  #          Defaults to 65_000
38
  def get_entry_stream!(%Unzip{} = unzip, %Unzip.Entry{file_name: file_name}, opts) do
39
    get_entry_stream!(unzip, file_name, opts)
16✔
40
  end
41

42
  def get_entry_stream!(%Unzip{} = unzip, file_name, opts) when is_bitstring(file_name) do
43
    create_resource(fn -> Unzip.file_stream!(unzip, file_name, opts) end)
16✔
44
  end
45

46
  def open(cbz_file_path) when is_bitstring(cbz_file_path) do
47
    with true <- File.exists?(cbz_file_path) || {:error, "Doesn't exist, #{cbz_file_path}"},
625✔
48
         %Unzip.LocalFile{} = zip_file <- Unzip.LocalFile.open(cbz_file_path) do
624✔
49
      Unzip.new(zip_file)
624✔
50
    end
51
  end
52

53
  def read(cbz_file_path, opts \\ []) do
54
    with {:ok, %{entries: file_entries, file: unzip}} <- get_entries(cbz_file_path, opts) do
622✔
55
      file_entries =
622✔
56
        file_entries
57
        |> Enum.map(fn entry ->
58
          entry
59
          |> Map.put(:stream_fun, fn -> get_entry_stream!(unzip, entry, opts) end)
2,488✔
60
        end)
61

62
      {:ok, %{entries: file_entries, file: unzip}}
63
    end
64
  end
65

66
  def close(%Unzip{zip: %Unzip.LocalFile{} = zip_file}) do
67
    close(zip_file)
10✔
68
  end
69

70
  def close(%Unzip.LocalFile{} = zip_file) do
71
    Unzip.LocalFile.close(zip_file)
10✔
72
  end
73
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc