flipbook 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9873e25f97a747f0f45e26e9eb9c503228d6b2daa975a8976f64480c1b3e0ba0
4
- data.tar.gz: 90bfb6579e71d4fdea9035fe86561fcde8a4911acb56f9ce8414136d0004abd6
3
+ metadata.gz: 9abd6bb4146e33beb424bec0c939348c93aa8ac9e80c3154b2cddc6bbc1f274d
4
+ data.tar.gz: 0210edbf204724a000f096fbdcec2cd58ee0af871805410083a90f60c3b982b5
5
5
  SHA512:
6
- metadata.gz: eb493019ec22fce32d0f4741bd1db36dbc8403b1528b267f8abb94b99865de2ceed88f50e24efdf145f760de33ea1526ce5206d258b6739043135a87da2ead85
7
- data.tar.gz: e9a8476651fbfbe0cf0ff3a8092b0a7c0d3b9ee80a50c95a9a3ae8e0394c8275c84f5be424ce7ed65bcfa722a1002546e98d2f57ae630dd5cd599608caedb937
6
+ metadata.gz: f5aafee5ed88fa52d775ff31ef699fea4dc37f6dddaaaf4dea883aba1ee59ff92c8c0f4cab238a560c8aa1ef634c99c31ff9145a958fa182edf515edd0ce8a9e
7
+ data.tar.gz: 06307e57f4225bb88a2894953d6f3ccac17366a2065308017c0043b969edc05bb06f5de651d32d1b1285624cf111e0f63f1c6cc499cd52e03d134aaf3ec93bad
data/.codespellignore ADDED
File without changes
data/.yamllint ADDED
@@ -0,0 +1,16 @@
1
+ extends: default
2
+ ignore: |
3
+ build/
4
+ node_modules/
5
+ runtime/build/
6
+ tmp/
7
+ **/*.dSYM/**
8
+
9
+ rules:
10
+ comments:
11
+ min-spaces-from-content: 1
12
+ document-start: disable
13
+ line-length:
14
+ max: 200
15
+ truthy:
16
+ check-keys: false
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.4.1] - 2026-09-26
4
+
5
+ - Preserve existing GIF and APNG files if writing a replacement fails.
6
+
3
7
  ## [0.4.0] - 2026-09-25
4
8
 
5
9
  - Read composited GIF frames with configurable image, frame, and total-pixel limits.
@@ -5,21 +5,8 @@ require "stringio"
5
5
  module Flipbook
6
6
  module APNG
7
7
  class Writer
8
- def self.open(path, **options)
9
- io = File.open(path, "wb")
10
- writer = new(io, **options)
11
- writer.instance_variable_set(:@owns_io, true)
12
- return writer unless block_given?
13
-
14
- begin
15
- yield writer
16
- ensure
17
- writer.close
18
- end
19
- path
20
- rescue StandardError
21
- io&.close unless io&.closed?
22
- raise
8
+ def self.open(path, **options, &block)
9
+ Output.open(self, path, **options, &block)
23
10
  end
24
11
 
25
12
  def initialize(io, width:, height:, loop: true, optimize: true, buffered: nil)
@@ -71,7 +58,7 @@ module Flipbook
71
58
  patch_animation_control
72
59
  end
73
60
  @closed = true
74
- @io.close if @owns_io && !@io.closed?
61
+ Output.finish(@io, @target_path, @target_mode) if @owns_io
75
62
  self
76
63
  end
77
64
 
@@ -3,21 +3,8 @@
3
3
  module Flipbook
4
4
  module GIF
5
5
  class Writer
6
- def self.open(path, **options)
7
- io = File.open(path, "wb")
8
- writer = new(io, **options)
9
- writer.instance_variable_set(:@owns_io, true)
10
- return writer unless block_given?
11
-
12
- begin
13
- yield writer
14
- ensure
15
- writer.close
16
- end
17
- path
18
- rescue StandardError
19
- io&.close unless io&.closed?
20
- raise
6
+ def self.open(path, **options, &block)
7
+ Output.open(self, path, **options, &block)
21
8
  end
22
9
 
23
10
  def initialize(io, width:, height:, loop: true, palette: :per_frame, colors: 256, dither: :floyd_steinberg, transparent_index: nil, optimize: true)
@@ -100,7 +87,7 @@ module Flipbook
100
87
  write_pending(@pending_frame[:transparent] ? 2 : 1)
101
88
  @io << ";".b
102
89
  @closed = true
103
- @io.close if @owns_io && !@io.closed?
90
+ Output.finish(@io, @target_path, @target_mode) if @owns_io
104
91
  self
105
92
  end
106
93
 
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "tempfile"
4
+
5
+ module Flipbook
6
+ module Output
7
+ module_function
8
+
9
+ def open(writer_class, path, **options)
10
+ target = File.expand_path(path)
11
+ mode = File.exist?(target) ? File.stat(target).mode & 0o777 : 0o666 & ~File.umask
12
+ io = Tempfile.new(".flipbook-", File.dirname(target))
13
+ io.binmode
14
+ writer = writer_class.new(io, **options)
15
+ writer.instance_variable_set(:@owns_io, true)
16
+ writer.instance_variable_set(:@target_path, target)
17
+ writer.instance_variable_set(:@target_mode, mode)
18
+ return writer unless block_given?
19
+
20
+ yield writer
21
+ writer.close
22
+ path
23
+ rescue Exception
24
+ io&.close!
25
+ raise
26
+ end
27
+
28
+ def finish(io, target, mode)
29
+ io.close unless io.closed?
30
+ File.chmod(mode, io.path)
31
+ File.rename(io.path, target)
32
+ rescue Exception
33
+ io.close!
34
+ raise
35
+ end
36
+ end
37
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Flipbook
4
- VERSION = "0.4.0"
4
+ VERSION = "0.4.1"
5
5
  end
data/lib/flipbook.rb CHANGED
@@ -4,6 +4,7 @@ require "tessel"
4
4
 
5
5
  require_relative "flipbook/version"
6
6
  require_relative "flipbook/timing"
7
+ require_relative "flipbook/output"
7
8
  require_relative "flipbook/gif/bit_writer"
8
9
  require_relative "flipbook/gif/lzw"
9
10
  require_relative "flipbook/gif/reader"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flipbook
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yudai Takada
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-09-25 00:00:00.000000000 Z
11
+ date: 2026-09-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tessel
@@ -66,6 +66,8 @@ executables: []
66
66
  extensions: []
67
67
  extra_rdoc_files: []
68
68
  files:
69
+ - ".codespellignore"
70
+ - ".yamllint"
69
71
  - CHANGELOG.md
70
72
  - LICENSE.txt
71
73
  - README.md
@@ -84,6 +86,7 @@ files:
84
86
  - lib/flipbook/gif/lzw.rb
85
87
  - lib/flipbook/gif/reader.rb
86
88
  - lib/flipbook/gif/writer.rb
89
+ - lib/flipbook/output.rb
87
90
  - lib/flipbook/timing.rb
88
91
  - lib/flipbook/version.rb
89
92
  - sig/flipbook.rbs