refile-postgres 1.3.0 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/lib/refile/postgres/backend.rb +2 -2
- data/lib/refile/postgres/backend/reader.rb +11 -0
- data/lib/refile/postgres/version.rb +1 -1
- data/spec/refile/postgres/backend_spec.rb +36 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3af65c53e11c0e9bfe133c1f90e96ad49129adab
|
4
|
+
data.tar.gz: aab1a3e85982632372366006e96757a221da3b62
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a2183cb351ee8b23d8a428f11777b210f64bc9a29ca644a86282ccb2d834bdce6999a30ca1e744a9f04ee636e3734d58464766e7f28059989f7d52a125c7fd27
|
7
|
+
data.tar.gz: 30cfa3e996a15e175f80716a23fea44dc81f1c023293de14963e7140233edb84175e38cddd8751c90b222d1605525e2a1051dbba31b76ea33dbc9d79a7ddc05c
|
data/.travis.yml
CHANGED
@@ -7,7 +7,7 @@ module Refile
|
|
7
7
|
DEFAULT_REGISTRY_TABLE = "refile_attachments"
|
8
8
|
DEFAULT_NAMESPACE = "default"
|
9
9
|
PG_LARGE_OBJECT_METADATA_TABLE = "pg_largeobject_metadata"
|
10
|
-
READ_CHUNK_SIZE =
|
10
|
+
READ_CHUNK_SIZE = 16384
|
11
11
|
|
12
12
|
def initialize(connection_or_proc, max_size: nil, namespace: DEFAULT_NAMESPACE, registry_table: DEFAULT_REGISTRY_TABLE)
|
13
13
|
@connection_or_proc = connection_or_proc
|
@@ -108,7 +108,7 @@ module Refile
|
|
108
108
|
}, [id.to_s.to_i])
|
109
109
|
oid = rez[0]['oid'].to_i
|
110
110
|
connection.lo_unlink(oid)
|
111
|
-
connection.exec_params("DELETE FROM #{registry_table} WHERE oid = $1::
|
111
|
+
connection.exec_params("DELETE FROM #{registry_table} WHERE oid = $1::oid;", [oid])
|
112
112
|
end
|
113
113
|
end
|
114
114
|
end
|
@@ -2,6 +2,7 @@ module Refile
|
|
2
2
|
module Postgres
|
3
3
|
class Backend
|
4
4
|
class Reader
|
5
|
+
STREAM_CHUNK_SIZE = 16384
|
5
6
|
include SmartTransaction
|
6
7
|
|
7
8
|
def initialize(connection_or_proc, oid)
|
@@ -43,6 +44,16 @@ module Refile
|
|
43
44
|
end
|
44
45
|
end
|
45
46
|
|
47
|
+
def each
|
48
|
+
if block_given?
|
49
|
+
until eof?
|
50
|
+
yield(read(STREAM_CHUNK_SIZE))
|
51
|
+
end
|
52
|
+
else
|
53
|
+
to_enum
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
46
57
|
def size
|
47
58
|
@size ||= fetch_size
|
48
59
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require "spec_helper"
|
2
|
+
require "tempfile"
|
2
3
|
|
3
4
|
describe Refile::Postgres::Backend do
|
4
5
|
let(:connection) { test_connection }
|
@@ -80,4 +81,39 @@ describe Refile::Postgres::Backend do
|
|
80
81
|
let(:connection_or_proc) { connection }
|
81
82
|
it_behaves_like :backend
|
82
83
|
end
|
84
|
+
|
85
|
+
describe "Content streaming" do
|
86
|
+
let(:connection_or_proc) { test_connection }
|
87
|
+
let(:backend) { Refile::Postgres::Backend.new(connection_or_proc, max_size: 1000000 ) }
|
88
|
+
it "allows to steam large file" do
|
89
|
+
expect(Refile::Postgres::Backend::Reader::STREAM_CHUNK_SIZE).to eq(16384)
|
90
|
+
uploadable = Tempfile.new("test-file")
|
91
|
+
uploadable.write "A" * Refile::Postgres::Backend::Reader::STREAM_CHUNK_SIZE
|
92
|
+
uploadable.write "B" * Refile::Postgres::Backend::Reader::STREAM_CHUNK_SIZE
|
93
|
+
uploadable.write "C" * Refile::Postgres::Backend::Reader::STREAM_CHUNK_SIZE
|
94
|
+
uploadable.close
|
95
|
+
uploadable.open
|
96
|
+
file = backend.upload(uploadable)
|
97
|
+
expect(backend.exists?(file.id)).to eq(true)
|
98
|
+
reader = backend.open(file.id)
|
99
|
+
enum = reader.each
|
100
|
+
expect(enum.next).to eq("A" * Refile::Postgres::Backend::Reader::STREAM_CHUNK_SIZE)
|
101
|
+
expect(enum.next).to eq("B" * Refile::Postgres::Backend::Reader::STREAM_CHUNK_SIZE)
|
102
|
+
expect(enum.next).to eq("C" * Refile::Postgres::Backend::Reader::STREAM_CHUNK_SIZE)
|
103
|
+
expect { enum.next }.to raise_error(StopIteration)
|
104
|
+
end
|
105
|
+
|
106
|
+
it "allows to steam small file" do
|
107
|
+
uploadable = Tempfile.new("test-file")
|
108
|
+
uploadable.write "QWERTY"
|
109
|
+
uploadable.close
|
110
|
+
uploadable.open
|
111
|
+
file = backend.upload(uploadable)
|
112
|
+
expect(backend.exists?(file.id)).to eq(true)
|
113
|
+
reader = backend.open(file.id)
|
114
|
+
enum = reader.each
|
115
|
+
expect(enum.next).to eq("QWERTY")
|
116
|
+
expect { enum.next }.to raise_error(StopIteration)
|
117
|
+
end
|
118
|
+
end
|
83
119
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: refile-postgres
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Krists Ozols
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-04-
|
11
|
+
date: 2016-04-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: refile
|