eac_fs 0.3.0 → 0.4.0

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: 42046162cfd331397663078e9dbd58c38e5fd5d05520afe4652380166d0d1b51
4
- data.tar.gz: 8123ecd08337c318867ade46153aad2cd6abf552a0dd0d1f74392b9923652833
3
+ metadata.gz: f84f3e6bee2753e30079a3e79cf4d8ad3568b59dfeac360f1de73d2ca34162d5
4
+ data.tar.gz: 184ab1296d60754f52dc2d598dec9b18871b1024dde617b3b2cac3d8b50c1490
5
5
  SHA512:
6
- metadata.gz: ed56297284fba8ee9639b10fc83fb6c1c5a4df5de4796609f3fb18020e1ed9184b408daeaf3562cb812bb01f5f5fcd174bab33f5570be2b1a69a322e0c09a522
7
- data.tar.gz: f73d940b0e962401e4465bd3c206ee83ec926ab5620591bffae110b251f92f11bfaeb0ac745a725f00370b65ada96e68d78ba880bcd78b76660643dabcd4f914
6
+ metadata.gz: 6c1b1a320116205e2c690564bdd3d6aa78451a0b26ef3feeb8a5cddf76b6a96e427e89bc5db02fd535b10453b61d01edd6211e075a2e9819b9f41bef809d1203
7
+ data.tar.gz: f4bc08f798e701a06a6dadf703eeb6d0c4c5a21c25cb95c5946b6aaf40ae13f9a015a8cb8ac6ffaac96abffefe71dc25e2bf9f6a8970bb2a149ce552306ab4f6
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_fs/patches'
4
+ require 'eac_ruby_utils/fs/temp'
5
+
6
+ module Avm
7
+ class CachedDownload
8
+ attr_reader :url, :fs_cache
9
+
10
+ def initialize(url, parent_fs_cache = nil)
11
+ @url = url
12
+ @fs_cache = (parent_fs_cache || fs_cache).child(url.parameterize)
13
+ end
14
+
15
+ def assert
16
+ download unless fs_cache.cached?
17
+ end
18
+
19
+ def download
20
+ ::EacRubyUtils::Fs::Temp.on_file do |temp|
21
+ download_to(temp)
22
+ fs_cache.content_path.to_pathname.dirname.mkpath
23
+ ::FileUtils.mv(temp.to_path, fs_cache.content_path)
24
+ end
25
+ end
26
+
27
+ def path
28
+ fs_cache.content_path.to_pathname
29
+ end
30
+
31
+ private
32
+
33
+ def download_to(local_file)
34
+ ::URI.parse(url).open do |remote|
35
+ local_file.open('wb') { |handle| handle.write(remote.read) }
36
+ end
37
+ end
38
+ end
39
+ end
@@ -6,6 +6,9 @@ require 'filemagic'
6
6
 
7
7
  module EacFs
8
8
  class FileInfo
9
+ UNKNOWN_CONTENT_TYPE_STRING = 'application/octet-stream'
10
+ UNKNOWN_CONTENT_TYPE = ::ContentType.parse(UNKNOWN_CONTENT_TYPE_STRING)
11
+
9
12
  enable_simple_cache
10
13
  attr_reader :magic_string
11
14
 
@@ -19,6 +22,8 @@ module EacFs
19
22
 
20
23
  def content_type_uncached
21
24
  ::ContentType.parse(magic_string)
25
+ rescue ::Parslet::ParseFailed
26
+ UNKNOWN_CONTENT_TYPE
22
27
  end
23
28
  end
24
29
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacFs
4
- VERSION = '0.3.0'
4
+ VERSION = '0.4.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eac_fs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Put here the authors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-09-24 00:00:00.000000000 Z
11
+ date: 2021-09-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: content-type
@@ -74,6 +74,7 @@ extra_rdoc_files: []
74
74
  files:
75
75
  - lib/eac_fs.rb
76
76
  - lib/eac_fs/cache.rb
77
+ - lib/eac_fs/cached_download.rb
77
78
  - lib/eac_fs/file_info.rb
78
79
  - lib/eac_fs/patches.rb
79
80
  - lib/eac_fs/patches/module.rb