large_object_store 1.3.2 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/Readme.md +1 -1
- data/lib/large_object_store/version.rb +1 -1
- data/lib/large_object_store.rb +19 -11
- metadata +4 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b62700b782559354a063c7b1f27d1a40fed24618ac7203e62f433a33ded2b46e
|
4
|
+
data.tar.gz: cfe940d1f9cbecbf8bb4619afc7604775f80a215580af336e57e98f88595cd44
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 875bfaffed85fb6b1d7476b9d82d8c588aedb93f01c7844bfd8518e311930b4ea466aa787ad75860d47f91614e17ce6cb3fcefb18db52855cf33df589ad1e4e6
|
7
|
+
data.tar.gz: 45b2baa7dbfb379f5b7d66e0c492aa2d7dff696b1e5d690942dfb53061c4fd1267eebe0eeca78446957309b9f1526405de38a416dcec5bff8c5a24451cbcafcd
|
data/Readme.md
CHANGED
@@ -33,4 +33,4 @@ acemacu@gmail.com<br/>
|
|
33
33
|
[Michael Grosser](https://github.com/grosser)<br/>
|
34
34
|
michael@grosser.it<br/>
|
35
35
|
License: MIT<br/>
|
36
|
-
[![
|
36
|
+
[![CI](https://github.com/anamartinez/large_object_store/actions/workflows/actions.yml/badge.svg)](https://github.com/anamartinez/large_object_store/actions/workflows/actions.yml)
|
data/lib/large_object_store.rb
CHANGED
@@ -12,17 +12,18 @@ module LargeObjectStore
|
|
12
12
|
NORMAL = 0
|
13
13
|
COMPRESSED = 1
|
14
14
|
RAW = 2
|
15
|
-
|
15
|
+
FLAG_RADIX = 32 # we can store 32 different states
|
16
16
|
|
17
|
-
def self.wrap(store)
|
18
|
-
RailsWrapper.new(store)
|
17
|
+
def self.wrap(store, **options)
|
18
|
+
RailsWrapper.new(store, options)
|
19
19
|
end
|
20
20
|
|
21
21
|
class RailsWrapper
|
22
22
|
attr_reader :store
|
23
23
|
|
24
|
-
def initialize(store)
|
24
|
+
def initialize(store, serializer: Marshal)
|
25
25
|
@store = store
|
26
|
+
@serializer = serializer
|
26
27
|
end
|
27
28
|
|
28
29
|
def write(key, value, options = {})
|
@@ -61,14 +62,20 @@ module LargeObjectStore
|
|
61
62
|
pages, uuid = @store.read(key(key, 0))
|
62
63
|
return if pages.nil?
|
63
64
|
|
64
|
-
data = if pages.is_a?(
|
65
|
+
data = if pages.is_a?(Integer)
|
65
66
|
# read sliced data
|
66
67
|
keys = (1..pages).map { |i| key(key, i) }
|
67
68
|
# use values_at to enforce key order because read_multi doesn't guarantee a return order
|
68
69
|
slices = @store.read_multi(*keys).values_at(*keys)
|
69
70
|
return nil if slices.compact.size != pages
|
70
|
-
|
71
|
+
|
72
|
+
slices = slices.map do |slice|
|
73
|
+
s = slice.dup
|
74
|
+
[s.slice!(0, UUID_SIZE), s]
|
75
|
+
end
|
76
|
+
|
71
77
|
return nil unless slices.map(&:first).uniq == [uuid]
|
78
|
+
|
72
79
|
slices.map!(&:last).join("")
|
73
80
|
else
|
74
81
|
pages
|
@@ -104,7 +111,7 @@ module LargeObjectStore
|
|
104
111
|
flag |= RAW
|
105
112
|
value = value.to_s
|
106
113
|
else
|
107
|
-
value =
|
114
|
+
value = @serializer.dump(value)
|
108
115
|
end
|
109
116
|
|
110
117
|
if compress?(value, options)
|
@@ -112,14 +119,15 @@ module LargeObjectStore
|
|
112
119
|
value = Zlib::Deflate.deflate(value)
|
113
120
|
end
|
114
121
|
|
115
|
-
value.prepend(flag.to_s(
|
122
|
+
value.prepend(flag.to_s(FLAG_RADIX))
|
116
123
|
end
|
117
124
|
|
118
125
|
# opposite operations and order of serialize
|
119
|
-
def deserialize(
|
120
|
-
|
126
|
+
def deserialize(raw_data)
|
127
|
+
data = raw_data.dup
|
128
|
+
flag = data.slice!(0, 1).to_i(FLAG_RADIX)
|
121
129
|
data = Zlib::Inflate.inflate(data) if flag & COMPRESSED == COMPRESSED
|
122
|
-
data =
|
130
|
+
data = @serializer.load(data) if flag & RAW != RAW
|
123
131
|
data
|
124
132
|
end
|
125
133
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: large_object_store
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ana Martinez
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-03-16 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email: acemacu@gmail.com
|
@@ -31,15 +31,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
31
31
|
requirements:
|
32
32
|
- - ">="
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version: '
|
34
|
+
version: '2.5'
|
35
35
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
36
|
requirements:
|
37
37
|
- - ">="
|
38
38
|
- !ruby/object:Gem::Version
|
39
39
|
version: '0'
|
40
40
|
requirements: []
|
41
|
-
|
42
|
-
rubygems_version: 2.5.1
|
41
|
+
rubygems_version: 3.1.6
|
43
42
|
signing_key:
|
44
43
|
specification_version: 4
|
45
44
|
summary: Store large objects in memcache or others
|