send_file_with_range 1.0.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 +7 -0
- data/lib/send_file_with_range.rb +3 -0
- data/lib/send_file_with_range/controller_extension.rb +40 -0
- data/lib/send_file_with_range/railtie.rb +11 -0
- metadata +49 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: fbdffd574f23efb4f2303dc19c060fc31b386797
|
4
|
+
data.tar.gz: 8b38579fd81f2b220273c919c3b2bdf2b92ce00c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d0fca68759c373bd73ff20930f9dded1dd2580320b7e622b8624736fdf37959ef446131697f8bef62c2a36341bff7b76e51f530606a38ac99b4402d1ab96a8a5
|
7
|
+
data.tar.gz: f7bb324ab61781e9dea1ca3fad811d6948d86af11ee9b3a9a9eafdb1a5606ff7971fa8d0b22b488a70d9de27beeaa83397ef81d1a3f9ea59c5e494a732e6ad8e
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module SendFileWithRange
|
2
|
+
module ControllerExtension
|
3
|
+
|
4
|
+
def self.included(base)
|
5
|
+
base.alias_method_chain :send_file, :range_option
|
6
|
+
end
|
7
|
+
|
8
|
+
def send_file_with_range_option(path, options = {})
|
9
|
+
if options[:range]
|
10
|
+
send_file_with_range(path, options)
|
11
|
+
else
|
12
|
+
send_file_without_range_option(path, options)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def send_file_with_range(path, options = {})
|
17
|
+
if File.exist?(path)
|
18
|
+
file_size = File.size(path)
|
19
|
+
begin_point = 0
|
20
|
+
end_point = file_size - 1
|
21
|
+
status = 200
|
22
|
+
if request.headers['range']
|
23
|
+
status = 206
|
24
|
+
if request.headers['range'] =~ /bytes\=(\d+)\-(\d*)/
|
25
|
+
begin_point = $1.to_i
|
26
|
+
end_point = $2.to_i if $2.present?
|
27
|
+
end
|
28
|
+
end
|
29
|
+
content_length = end_point - begin_point + 1
|
30
|
+
response.header['Content-Range'] = "bytes #{begin_point}-#{end_point}/#{file_size}"
|
31
|
+
response.header['Content-Length'] = content_length.to_s
|
32
|
+
response.header['Accept-Ranges'] = 'bytes'
|
33
|
+
send_data IO.binread(path, content_length, begin_point), options.merge(:status => status)
|
34
|
+
else
|
35
|
+
raise ActionController::MissingFile, "Cannot read file #{path}"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'send_file_with_range/controller_extension'
|
2
|
+
|
3
|
+
module SendFileWithRange
|
4
|
+
class Railtie < ::Rails::Railtie
|
5
|
+
|
6
|
+
initializer 'send_file_with_range.include' do
|
7
|
+
ActionController::DataStreaming.send :include, SendFileWithRange::ControllerExtension
|
8
|
+
end
|
9
|
+
|
10
|
+
end
|
11
|
+
end
|
metadata
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: send_file_with_range
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Adam Cooke
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-12-10 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A Rails addition which will allow sending of files with appropriate range
|
14
|
+
headers
|
15
|
+
email:
|
16
|
+
- me@adamcooke.io
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- lib/send_file_with_range.rb
|
22
|
+
- lib/send_file_with_range/controller_extension.rb
|
23
|
+
- lib/send_file_with_range/railtie.rb
|
24
|
+
homepage: https://github.com/adamcooke/send_file_with_rangeit
|
25
|
+
licenses:
|
26
|
+
- MIT
|
27
|
+
metadata: {}
|
28
|
+
post_install_message:
|
29
|
+
rdoc_options: []
|
30
|
+
require_paths:
|
31
|
+
- lib
|
32
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
33
|
+
requirements:
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '0'
|
37
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
requirements: []
|
43
|
+
rubyforge_project:
|
44
|
+
rubygems_version: 2.4.5
|
45
|
+
signing_key:
|
46
|
+
specification_version: 4
|
47
|
+
summary: A Rails addition which will allow sending of files with appropriate range
|
48
|
+
headers
|
49
|
+
test_files: []
|