postgresql_lo_streamer 1.2.0 → 1.2.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
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9ed951b55d69c47c78e0bb532c588d767f103001
|
4
|
+
data.tar.gz: 6d459d8a27c0fdbc555c2969ff85bad967e22ad7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bca54aa210afd1b84ceb633e1a9c8ef90e53daa4419a1590ea23bdd2de148047d2b14ebdaa41c48d6dc92fb96a97f85df35404de001f0d2b913cb2aed962bec3
|
7
|
+
data.tar.gz: 22c17d889d92c8f1b42d981597155ecde4587d224d67c17be35075fcee2c5d228abe30fb43384df96b8217184698f432c128092c4d5a45152d57f1025e22fe63
|
@@ -2,25 +2,21 @@
|
|
2
2
|
|
3
3
|
module PostgresqlLoStreamer
|
4
4
|
class LoController < ActionController::Base
|
5
|
+
|
5
6
|
def stream
|
6
|
-
send_file_headers!(headers_for_extension_or_default)
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
streamer = PostgresqlLoStreamer::Streamer.new(
|
9
|
+
connection,
|
10
|
+
params[:id].to_i
|
11
|
+
)
|
12
|
+
send_file_headers!(default_headers_for(params[:format]))
|
13
|
+
if !streamer.object_exists?
|
14
|
+
head 404, default_headers_for(params[:format])
|
15
|
+
return
|
12
16
|
end
|
13
|
-
|
14
17
|
self.status = 200
|
15
|
-
self.response_body =
|
16
|
-
|
17
|
-
lo = connection.lo_open(object_identifier, ::PG::INV_READ)
|
18
|
-
while data = connection.lo_read(lo, 4096) do
|
19
|
-
y << data
|
20
|
-
end
|
21
|
-
connection.lo_close(lo)
|
22
|
-
end
|
23
|
-
end
|
18
|
+
self.response_body = streamer.stream
|
19
|
+
|
24
20
|
end
|
25
21
|
|
26
22
|
def connection
|
@@ -29,29 +25,9 @@ module PostgresqlLoStreamer
|
|
29
25
|
|
30
26
|
private
|
31
27
|
|
32
|
-
def
|
33
|
-
|
34
|
-
|
35
|
-
rescue PG::Error => e
|
36
|
-
if e.to_s.include? "does not exist"
|
37
|
-
return false
|
38
|
-
end
|
39
|
-
|
40
|
-
raise
|
41
|
-
end
|
42
|
-
|
43
|
-
return true
|
44
|
-
end
|
45
|
-
|
46
|
-
def configuration
|
47
|
-
PostgresqlLoStreamer.configuration
|
48
|
-
end
|
49
|
-
|
50
|
-
def headers_for_extension_or_default
|
51
|
-
#extension provided and recognized
|
52
|
-
#Mime is built into rails
|
53
|
-
if params[:format].present? && Mime::Type.lookup_by_extension(params[:format]).present?
|
54
|
-
type = Mime::Type.lookup_by_extension(params[:format]).to_s
|
28
|
+
def default_headers_for(extension)
|
29
|
+
if extension.present? && Mime::Type.lookup_by_extension(extension).present?
|
30
|
+
type = Mime::Type.lookup_by_extension(extension).to_s
|
55
31
|
{type: type, disposition: disposition_from_type(type) }
|
56
32
|
else
|
57
33
|
configuration.options #fallback
|
@@ -75,5 +51,9 @@ module PostgresqlLoStreamer
|
|
75
51
|
end
|
76
52
|
end
|
77
53
|
|
54
|
+
def configuration
|
55
|
+
PostgresqlLoStreamer.configuration
|
56
|
+
end
|
57
|
+
|
78
58
|
end
|
79
59
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
class PostgresqlLoStreamer::Streamer
|
2
|
+
attr_accessor :connection, :object_identifier
|
3
|
+
|
4
|
+
def initialize(connection, object_identifier)
|
5
|
+
@connection = connection
|
6
|
+
@object_identifier = object_identifier
|
7
|
+
end
|
8
|
+
|
9
|
+
def object_exists?
|
10
|
+
begin
|
11
|
+
@connection.lo_open(@object_identifier, ::PG::INV_READ)
|
12
|
+
rescue PG::Error => e
|
13
|
+
if e.to_s.include? "does not exist"
|
14
|
+
return false
|
15
|
+
end
|
16
|
+
raise
|
17
|
+
end
|
18
|
+
return true
|
19
|
+
end
|
20
|
+
|
21
|
+
def stream
|
22
|
+
return Enumerator.new do |y|
|
23
|
+
@connection.transaction do
|
24
|
+
lo = @connection.lo_open(@object_identifier, ::PG::INV_READ)
|
25
|
+
while data = connection.lo_read(lo, 4096) do
|
26
|
+
y << data
|
27
|
+
end
|
28
|
+
@connection.lo_close(lo)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: postgresql_lo_streamer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Diogo Biazus
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-09-
|
11
|
+
date: 2017-09-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -82,6 +82,7 @@ files:
|
|
82
82
|
- lib/postgresql_lo_streamer.rb
|
83
83
|
- lib/postgresql_lo_streamer/configuration.rb
|
84
84
|
- lib/postgresql_lo_streamer/engine.rb
|
85
|
+
- lib/postgresql_lo_streamer/streamer.rb
|
85
86
|
- lib/postgresql_lo_streamer/version.rb
|
86
87
|
- lib/tasks/postgresql_lo_streamer_tasks.rake
|
87
88
|
homepage: https://github.com/diogob/postgresql_lo_streamer
|