tus-server 0.10.0 → 0.10.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +32 -1
- data/lib/tus/checksum.rb +3 -3
- data/lib/tus/server.rb +1 -1
- data/lib/tus/storage/filesystem.rb +1 -1
- data/lib/tus/storage/gridfs.rb +5 -6
- data/lib/tus/storage/s3.rb +4 -9
- data/tus-server.gemspec +1 -1
- 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: 0e7ec2a89ccbb20c13484b06734c5a8892eef8c1
|
4
|
+
data.tar.gz: 8d00f4e4f025bd5292979d2b33582a13aca157eb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0e4cae19bb8f3a3499f07347b2884e5aaa9bd740842cb0729b6228d93b573ddb3a9aa1ea1bb9ababa587614ed59ce481d61759b8d9ad3ac5e0894f984c57e694
|
7
|
+
data.tar.gz: 46c5ede8052c0e7873ce47809e11caef2bc248d18364426e6b7f9ce77478df3fdfee860c1d2a79e4a7189089f1b49f9b0df938c2447255140e5367c71b3dfa5d
|
data/README.md
CHANGED
@@ -4,7 +4,7 @@ A Ruby server for the [tus resumable upload protocol]. It implements the core
|
|
4
4
|
1.0 protocol, along with the following extensions:
|
5
5
|
|
6
6
|
* [`creation`][creation] (and `creation-defer-length`)
|
7
|
-
* [`concatenation`][concatenation]
|
7
|
+
* [`concatenation`][concatenation]
|
8
8
|
* [`checksum`][checksum]
|
9
9
|
* [`expiration`][expiration]
|
10
10
|
* [`termination`][termination]
|
@@ -96,6 +96,12 @@ client = Mongo::Client.new("mongodb://127.0.0.1:27017/mydb")
|
|
96
96
|
Tus::Server.opts[:storage] = Tus::Storage::Gridfs.new(client: client)
|
97
97
|
```
|
98
98
|
|
99
|
+
You can change the database prefix (defaults to `fs`):
|
100
|
+
|
101
|
+
```rb
|
102
|
+
Tus::Storage::Gridfs.new(client: client, prefix: "fs_temp")
|
103
|
+
```
|
104
|
+
|
99
105
|
By default MongoDB Gridfs stores files in chunks of 256KB, but you can change
|
100
106
|
that with the `:chunk_size` option:
|
101
107
|
|
@@ -290,6 +296,31 @@ the tus server), until it has been moved to a permanent storage. You might also
|
|
290
296
|
want to consider copying finished uploads to permanent storage directly from
|
291
297
|
the underlying tus storage, instead of downloading them through the app.
|
292
298
|
|
299
|
+
## Tests
|
300
|
+
|
301
|
+
Run tests with
|
302
|
+
|
303
|
+
```
|
304
|
+
$ rake test
|
305
|
+
```
|
306
|
+
|
307
|
+
The S3 tests are excluded by default, but you can include them by setting the
|
308
|
+
`$S3` environment variable.
|
309
|
+
|
310
|
+
```
|
311
|
+
$ S3=1 rake test
|
312
|
+
```
|
313
|
+
|
314
|
+
For running S3 tests you need to create an `.env` with the S3 credentials:
|
315
|
+
|
316
|
+
```sh
|
317
|
+
# .env
|
318
|
+
S3_BUCKET="..."
|
319
|
+
S3_REGION="..."
|
320
|
+
S3_ACCESS_KEY_ID="..."
|
321
|
+
S3_SECRET_ACCESS_KEY="..."
|
322
|
+
```
|
323
|
+
|
293
324
|
## Inspiration
|
294
325
|
|
295
326
|
The tus-ruby-server was inspired by [rubytus].
|
data/lib/tus/checksum.rb
CHANGED
@@ -47,14 +47,14 @@ module Tus
|
|
47
47
|
end
|
48
48
|
|
49
49
|
def generate_crc32(io)
|
50
|
-
crc =
|
51
|
-
crc = Zlib.crc32(io.read(16*1024, buffer ||= "")
|
50
|
+
crc = 0
|
51
|
+
crc = Zlib.crc32(io.read(16*1024, buffer ||= ""), crc) until io.eof?
|
52
52
|
Base64.encode64(crc.to_s)
|
53
53
|
end
|
54
54
|
|
55
55
|
def digest(name, io)
|
56
56
|
digest = Digest.const_get(name).new
|
57
|
-
digest.update(io.read(16*1024, buffer ||= "")
|
57
|
+
digest.update(io.read(16*1024, buffer ||= "")) until io.eof?
|
58
58
|
digest.base64digest
|
59
59
|
end
|
60
60
|
end
|
data/lib/tus/server.rb
CHANGED
@@ -81,7 +81,7 @@ module Tus
|
|
81
81
|
remaining_length = length
|
82
82
|
|
83
83
|
while remaining_length > 0
|
84
|
-
chunk = file.read([16*1024, remaining_length].min
|
84
|
+
chunk = file.read([16*1024, remaining_length].min) or break
|
85
85
|
remaining_length -= chunk.bytesize
|
86
86
|
yielder << chunk
|
87
87
|
end
|
data/lib/tus/storage/gridfs.rb
CHANGED
@@ -11,11 +11,12 @@ module Tus
|
|
11
11
|
attr_reader :client, :prefix, :bucket, :chunk_size
|
12
12
|
|
13
13
|
def initialize(client:, prefix: "fs", chunk_size: 256*1024)
|
14
|
-
@client
|
15
|
-
@prefix
|
16
|
-
@bucket = @client.database.fs(bucket_name: @prefix)
|
17
|
-
@bucket.send(:ensure_indexes!)
|
14
|
+
@client = client
|
15
|
+
@prefix = prefix
|
18
16
|
@chunk_size = chunk_size
|
17
|
+
@bucket = client.database.fs(bucket_name: prefix)
|
18
|
+
|
19
|
+
@bucket.send(:ensure_indexes!)
|
19
20
|
end
|
20
21
|
|
21
22
|
def create_file(uid, info = {})
|
@@ -131,8 +132,6 @@ module Tus
|
|
131
132
|
else
|
132
133
|
yielder << data
|
133
134
|
end
|
134
|
-
|
135
|
-
data.clear # deallocate chunk string
|
136
135
|
end
|
137
136
|
end
|
138
137
|
|
data/lib/tus/storage/s3.rb
CHANGED
@@ -67,15 +67,15 @@ module Tus
|
|
67
67
|
raise error
|
68
68
|
end
|
69
69
|
|
70
|
-
def patch_file(uid,
|
70
|
+
def patch_file(uid, input, info = {})
|
71
71
|
upload_id = info["multipart_id"]
|
72
72
|
part_number = info["multipart_parts"].count + 1
|
73
73
|
|
74
74
|
multipart_upload = object(uid).multipart_upload(upload_id)
|
75
75
|
multipart_part = multipart_upload.part(part_number)
|
76
|
-
md5 = Tus::Checksum.new("md5").generate(
|
76
|
+
md5 = Tus::Checksum.new("md5").generate(input)
|
77
77
|
|
78
|
-
response = multipart_part.upload(body:
|
78
|
+
response = multipart_part.upload(body: input, content_md5: md5)
|
79
79
|
|
80
80
|
info["multipart_parts"] << {
|
81
81
|
"part_number" => part_number,
|
@@ -113,12 +113,7 @@ module Tus
|
|
113
113
|
object = object(uid)
|
114
114
|
range = "bytes=#{range.begin}-#{range.end}" if range
|
115
115
|
|
116
|
-
raw_chunks =
|
117
|
-
object.get(range: range) do |chunk|
|
118
|
-
yielder << chunk
|
119
|
-
chunk.clear # deallocate string
|
120
|
-
end
|
121
|
-
end
|
116
|
+
raw_chunks = object.enum_for(:get, range: range)
|
122
117
|
|
123
118
|
# Start the request to be notified if the object doesn't exist, and to
|
124
119
|
# get Aws::S3::Object#content_length.
|
data/tus-server.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tus-server
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.10.
|
4
|
+
version: 0.10.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Janko Marohnić
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-04-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: roda
|