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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: d6d0f7f1ebac87648a577460036f4e3b01565544
4
- data.tar.gz: 1a87e968454bd3360ae875d02004d469dab5f79a
2
+ SHA256:
3
+ metadata.gz: b62700b782559354a063c7b1f27d1a40fed24618ac7203e62f433a33ded2b46e
4
+ data.tar.gz: cfe940d1f9cbecbf8bb4619afc7604775f80a215580af336e57e98f88595cd44
5
5
  SHA512:
6
- metadata.gz: 86a7f612778fe0f5b63b822b7f7e1302893dc2d607cf1e2ac486ecc87c33f05e9dd5684ca427d4589b7c5c89c5419bcd57c5dc1f294ee92b0db507efe38843d3
7
- data.tar.gz: 2ec27c191e58e87c329dc17871805388c84967ba17e4bea6d36e03d5fb5a13d369062f26c8fb710abaa90a00950f1e61504e1b378e7316737392999744c85639
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
- [![Build Status](https://travis-ci.org/anamartinez/large_object_store.png)](https://travis-ci.org/anamartinez/large_object_store)
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)
@@ -1,3 +1,3 @@
1
1
  module LargeObjectStore
2
- VERSION = "1.3.2"
2
+ VERSION = "1.4.0"
3
3
  end
@@ -12,17 +12,18 @@ module LargeObjectStore
12
12
  NORMAL = 0
13
13
  COMPRESSED = 1
14
14
  RAW = 2
15
- RADIX = 32 # we can store 32 different states
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?(Fixnum)
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
- slices.map! { |s| [s.slice!(0, UUID_SIZE), s] }
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 = Marshal.dump(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(RADIX))
122
+ value.prepend(flag.to_s(FLAG_RADIX))
116
123
  end
117
124
 
118
125
  # opposite operations and order of serialize
119
- def deserialize(data)
120
- flag = data.slice!(0, 1).to_i(RADIX)
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 = Marshal.load(data) if flag & RAW != RAW
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.3.2
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: 2017-04-11 00:00:00.000000000 Z
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: '0'
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
- rubyforge_project:
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