Class: MP4::Source::Local
- Inherits:
-
Object
- Object
- MP4::Source::Local
- Includes:
- Base
- Defined in:
- lib/mp4/source/local.rb
Constant Summary
Constants included from Base
Instance Attribute Summary collapse
-
#path_to_file ⇒ Object
readonly
Returns the value of attribute path_to_file.
Class Method Summary collapse
Instance Method Summary collapse
- #close ⇒ Object
- #eof? ⇒ Boolean
-
#initialize(path_to_file) ⇒ Local
constructor
A new instance of Local.
- #mtime ⇒ Object
- #open! ⇒ Object
- #pos ⇒ Object
- #read(n) ⇒ Object
- #reset_seek ⇒ Object
- #set_seek(n) ⇒ Object
- #uri ⇒ Object
Methods included from Base
Constructor Details
#initialize(path_to_file) ⇒ Local
Returns a new instance of Local.
29 30 31 |
# File 'lib/mp4/source/local.rb', line 29 def initialize(path_to_file) @path_to_file = path_to_file.to_s end |
Instance Attribute Details
#path_to_file ⇒ Object (readonly)
Returns the value of attribute path_to_file.
5 6 7 |
# File 'lib/mp4/source/local.rb', line 5 def path_to_file @path_to_file end |
Class Method Details
.from_uri(uri, base_dir: nil) ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/mp4/source/local.rb', line 7 def self.from_uri(uri, base_dir: nil) raise ArgumentError, "expected local: URI, got #{uri.inspect}" unless uri.start_with?('local:') path = uri.sub(/\Alocal:/, '') resolved = resolve_path(path, base_dir) new(resolved.to_s) end |
.resolve_path(path, base_dir) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/mp4/source/local.rb', line 15 def self.resolve_path(path, base_dir) candidate = Pathname.new(path) return candidate if base_dir.nil? root = Pathname.new(base_dir). absolute = (candidate.absolute? ? candidate : root.join(candidate)). unless absolute.to_s.start_with?(root.to_s + File::SEPARATOR) || absolute.to_s == root.to_s raise ArgumentError, "path escapes base_dir: #{path.inspect}" end absolute end |
Instance Method Details
#close ⇒ Object
68 69 70 71 |
# File 'lib/mp4/source/local.rb', line 68 def close @file&.close @file = nil end |
#eof? ⇒ Boolean
54 55 56 |
# File 'lib/mp4/source/local.rb', line 54 def eof? file.eof? end |
#mtime ⇒ Object
62 63 64 65 66 |
# File 'lib/mp4/source/local.rb', line 62 def mtime File.mtime(@path_to_file) rescue Errno::ENOENT nil end |
#open! ⇒ Object
49 50 51 52 |
# File 'lib/mp4/source/local.rb', line 49 def open! file self end |
#pos ⇒ Object
58 59 60 |
# File 'lib/mp4/source/local.rb', line 58 def pos file.pos end |
#read(n) ⇒ Object
37 38 39 |
# File 'lib/mp4/source/local.rb', line 37 def read(n) file.read(n) end |
#reset_seek ⇒ Object
45 46 47 |
# File 'lib/mp4/source/local.rb', line 45 def reset_seek file.seek(0) end |
#set_seek(n) ⇒ Object
41 42 43 |
# File 'lib/mp4/source/local.rb', line 41 def set_seek(n) file.seek(n) end |
#uri ⇒ Object
33 34 35 |
# File 'lib/mp4/source/local.rb', line 33 def uri "local:#{@path_to_file}" end |