shrine-gridfs 1.0.1 → 1.0.2
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 +4 -4
- data/lib/shrine/storage/gridfs.rb +23 -29
- data/shrine-gridfs.gemspec +1 -1
- metadata +3 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f0a6b4ad0272f86f28fafde7d6ff7ccfc0831b1bd2b6be2a0fe19bc8cd981342
|
|
4
|
+
data.tar.gz: 98d7a698d6fb36b7ffe1e6da7d8561c926bd957aded29926a388ec4080492ed8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: bb4495e2df3506e5b41259d5e452dafc6b49400a836891c621f0f75162ffeed9324c4d35fb655edd93758dbb018458055c750d94b45739ec8d72436e44de31c0
|
|
7
|
+
data.tar.gz: aa01f4ef342402663ae6a7a0da5e79d99a70596c64d06cdb32737b0aec0036dc39decd51c40b21b3b607ba2d7547e7ec2d11935a74eb05d77d5cdd17aabeacf4
|
|
@@ -72,24 +72,34 @@ class Shrine
|
|
|
72
72
|
private
|
|
73
73
|
|
|
74
74
|
def create(io, id, shrine_metadata: {})
|
|
75
|
-
|
|
75
|
+
filename = shrine_metadata["filename"] || id
|
|
76
|
+
options = {
|
|
77
|
+
content_type: shrine_metadata["mime_type"] || "application/octet-stream",
|
|
78
|
+
metadata: shrine_metadata,
|
|
79
|
+
chunk_size: chunk_size,
|
|
80
|
+
}
|
|
76
81
|
|
|
77
|
-
|
|
78
|
-
chunk = io.read([@batch_size, chunk_size].max, buffer ||= "")
|
|
79
|
-
grid_chunks = Mongo::Grid::File::Chunk.split(chunk, file.info, offset ||= 0)
|
|
82
|
+
stream = bucket.open_upload_stream(filename, options)
|
|
80
83
|
|
|
81
|
-
|
|
84
|
+
# write in batches to avoid loading the whole file into memory; each
|
|
85
|
+
# batch must be a multiple of chunk size so that only the last chunk
|
|
86
|
+
# is allowed to be smaller
|
|
87
|
+
batch_size = (@batch_size.to_f / chunk_size).ceil * chunk_size
|
|
82
88
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
89
|
+
begin
|
|
90
|
+
until io.eof?
|
|
91
|
+
batch = io.read(batch_size, buffer ||= String.new)
|
|
92
|
+
stream.write(batch)
|
|
93
|
+
batch.clear # deallocate string
|
|
94
|
+
end
|
|
95
|
+
rescue
|
|
96
|
+
stream.abort
|
|
97
|
+
raise
|
|
86
98
|
end
|
|
87
99
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
md5: file.info.md5.hexdigest,
|
|
92
|
-
})
|
|
100
|
+
stream.close
|
|
101
|
+
|
|
102
|
+
id.replace(stream.file_id.to_s + File.extname(id))
|
|
93
103
|
end
|
|
94
104
|
|
|
95
105
|
def copy(io, id, shrine_metadata: {})
|
|
@@ -125,22 +135,6 @@ class Shrine
|
|
|
125
135
|
io.is_a?(UploadedFile) && io.storage.is_a?(Storage::Gridfs)
|
|
126
136
|
end
|
|
127
137
|
|
|
128
|
-
def create_file(id, shrine_metadata: {})
|
|
129
|
-
file = Mongo::Grid::File.new("",
|
|
130
|
-
filename: shrine_metadata["filename"] || id,
|
|
131
|
-
content_type: shrine_metadata["mime_type"] || "application/octet-stream",
|
|
132
|
-
metadata: shrine_metadata,
|
|
133
|
-
chunk_size: chunk_size,
|
|
134
|
-
)
|
|
135
|
-
|
|
136
|
-
bucket.insert_one(file)
|
|
137
|
-
|
|
138
|
-
id.replace(file.id.to_s + File.extname(id))
|
|
139
|
-
file.info.document[:md5] = Digest::MD5.new
|
|
140
|
-
|
|
141
|
-
file
|
|
142
|
-
end
|
|
143
|
-
|
|
144
138
|
def bson_id(id)
|
|
145
139
|
BSON::ObjectId(File.basename(id, ".*"))
|
|
146
140
|
end
|
data/shrine-gridfs.gemspec
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: shrine-gridfs
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0.
|
|
4
|
+
version: 1.0.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Janko Marohnić
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: shrine
|
|
@@ -92,7 +91,6 @@ dependencies:
|
|
|
92
91
|
- - ">="
|
|
93
92
|
- !ruby/object:Gem::Version
|
|
94
93
|
version: '0'
|
|
95
|
-
description:
|
|
96
94
|
email:
|
|
97
95
|
- janko.marohnic@gmail.com
|
|
98
96
|
executables: []
|
|
@@ -107,7 +105,6 @@ homepage: https://github.com/shrinerb/shrine-gridfs
|
|
|
107
105
|
licenses:
|
|
108
106
|
- MIT
|
|
109
107
|
metadata: {}
|
|
110
|
-
post_install_message:
|
|
111
108
|
rdoc_options: []
|
|
112
109
|
require_paths:
|
|
113
110
|
- lib
|
|
@@ -122,8 +119,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
122
119
|
- !ruby/object:Gem::Version
|
|
123
120
|
version: '0'
|
|
124
121
|
requirements: []
|
|
125
|
-
rubygems_version:
|
|
126
|
-
signing_key:
|
|
122
|
+
rubygems_version: 4.0.20
|
|
127
123
|
specification_version: 4
|
|
128
124
|
summary: Provides MongoDB's GridFS storage for Shrine.
|
|
129
125
|
test_files: []
|