tus-server 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +43 -20
- data/lib/tus/checksum.rb +4 -2
- data/lib/tus/errors.rb +2 -0
- data/lib/tus/info.rb +1 -0
- data/lib/tus/input.rb +1 -0
- data/lib/tus/server.rb +1 -0
- data/lib/tus/server/goliath.rb +3 -0
- data/lib/tus/storage/filesystem.rb +1 -0
- data/lib/tus/storage/gridfs.rb +1 -0
- data/lib/tus/storage/s3.rb +12 -6
- 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: 0016bea27534678199b2a3631ab710a9bb4bfd71
|
4
|
+
data.tar.gz: d2026f565ba010d7e6e64e9ab89bd06a1afc2be0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0c11c877cad9b293df94ec7859bfea15b40f9401c99ea593a1662e9735ba6c4d216cf986b5f761e8c81d5bee6081ac49686dc3550682f6b695c08c39a7306a9b
|
7
|
+
data.tar.gz: 19671d54820222ebb0855df11da3d673975e8e50afa3fe1f3ab30659b23cdaadc45e71100923c132562f348856949d3e216816800278e96d729ce5ff8f88455c
|
data/README.md
CHANGED
@@ -42,7 +42,7 @@ endpoint:
|
|
42
42
|
// using tus-js-client
|
43
43
|
new tus.Upload(file, {
|
44
44
|
endpoint: "http://localhost:9292/files",
|
45
|
-
chunkSize: 5*1024*1024, // required unless using Goliath
|
45
|
+
chunkSize: 5*1024*1024, // required unless using Goliath or Unicorn
|
46
46
|
// ...
|
47
47
|
})
|
48
48
|
```
|
@@ -53,39 +53,62 @@ nicely with tus-ruby-server, see [shrine-tus-demo] for an example integration.
|
|
53
53
|
|
54
54
|
### Goliath
|
55
55
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
also allows tus-ruby-server to handle interrupted requests, by saving
|
60
|
-
has been uploaded until the interruption. This means that with
|
61
|
-
**not** mandatory for client to chunk the upload into multiple
|
62
|
-
order to achieve resumable
|
63
|
-
servers.
|
56
|
+
Among all the existing Ruby web servers, [Goliath] is probably the ideal one to
|
57
|
+
run tus-ruby-server on. It's built on top of [EventMachine], making it
|
58
|
+
asynchronous both in reading the request body and writing to the response body.
|
59
|
+
Goliath also allows tus-ruby-server to handle interrupted requests, by saving
|
60
|
+
data that has been uploaded until the interruption. This means that with
|
61
|
+
Goliath it's **not** mandatory for client to chunk the upload into multiple
|
62
|
+
requests in order to achieve resumable upload (which would be the case for most
|
63
|
+
other web servers).
|
64
64
|
|
65
|
-
|
66
|
-
|
65
|
+
It's recommended that you use [goliath-rack_proxy] for running your tus server
|
66
|
+
app:
|
67
67
|
|
68
68
|
```rb
|
69
69
|
# Gemfile
|
70
70
|
gem "tus-server", "~> 1.0"
|
71
|
-
gem "goliath"
|
72
|
-
gem "async-rack", ">= 0.5.1"
|
71
|
+
gem "goliath-rack_proxy"
|
73
72
|
```
|
74
73
|
```rb
|
75
74
|
# tus.rb
|
76
|
-
require "tus/server
|
75
|
+
require "tus/server"
|
76
|
+
require "goliath/rack_proxy"
|
77
77
|
|
78
78
|
# any additional Tus::Server configuration you want to put in here
|
79
|
+
|
80
|
+
class GoliathTusServer < Goliath::RackProxy
|
81
|
+
rack_app Tus::Server
|
82
|
+
rewindable_input false # set to true if you're using checksums
|
83
|
+
end
|
79
84
|
```
|
80
85
|
```sh
|
81
86
|
$ ruby tus.rb --stdout # enable logging
|
82
87
|
```
|
83
88
|
|
84
|
-
|
85
|
-
|
86
|
-
Goliath
|
87
|
-
|
88
|
-
|
89
|
+
### Unicorn
|
90
|
+
|
91
|
+
Like Goliath, Unicorn also support streaming uploads, and tus-ruby-server knows
|
92
|
+
how to automatically recover from `Unicorn::ClientShutdown` exceptions during
|
93
|
+
upload, storing data that it has received up until that point. Just note that
|
94
|
+
in order to achieve streaming uploads, Nginx should be configured **not** to
|
95
|
+
buffer incoming requests.
|
96
|
+
|
97
|
+
But it's also fine to have Nginx buffer requests, just note that in this case
|
98
|
+
Nginx won't forward incomplete upload requests to tus-ruby-server, so in order
|
99
|
+
for resumable upload to be possible the client needs to send data in multiple
|
100
|
+
upload requests (which can then be retried individually).
|
101
|
+
|
102
|
+
### Other web servers
|
103
|
+
|
104
|
+
It's perfectly feasible to run tus-ruby-server on web servers other than
|
105
|
+
Goliath or Unicorn (even necessary if you want to run it inside another app).
|
106
|
+
Just keep in mind that most other web servers don't support request streaming,
|
107
|
+
which means that tus-ruby-server will be able to start processing upload
|
108
|
+
requess only once the whole request body has been received. Additionally,
|
109
|
+
incomplete upload requests won't be forwarded to tus-ruby-server, so in order
|
110
|
+
for resumable upload to be possible the client needs to send data in multiple
|
111
|
+
upload requests (which can then be retried individually).
|
89
112
|
|
90
113
|
## Storage
|
91
114
|
|
@@ -311,4 +334,4 @@ The tus-ruby-server was inspired by [rubytus].
|
|
311
334
|
[Range requests]: https://tools.ietf.org/html/rfc7233
|
312
335
|
[Goliath]: https://github.com/postrank-labs/goliath
|
313
336
|
[EventMachine]: https://github.com/eventmachine/eventmachine
|
314
|
-
[goliath
|
337
|
+
[goliath-rack_proxy]: https://github.com/janko-m/goliath-rack_proxy
|
data/lib/tus/checksum.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen-string-literal: true
|
2
|
+
|
1
3
|
module Tus
|
2
4
|
class Checksum
|
3
5
|
CHUNK_SIZE = 16*1024
|
@@ -48,7 +50,7 @@ module Tus
|
|
48
50
|
require "zlib"
|
49
51
|
require "base64"
|
50
52
|
crc = Zlib.crc32("")
|
51
|
-
while (data = io.read(CHUNK_SIZE, buffer ||=
|
53
|
+
while (data = io.read(CHUNK_SIZE, buffer ||= String.new))
|
52
54
|
crc = Zlib.crc32(data, crc)
|
53
55
|
end
|
54
56
|
Base64.strict_encode64(crc.to_s)
|
@@ -57,7 +59,7 @@ module Tus
|
|
57
59
|
def digest(name, io)
|
58
60
|
require "digest"
|
59
61
|
digest = Digest.const_get(name).new
|
60
|
-
while (data = io.read(CHUNK_SIZE, buffer ||=
|
62
|
+
while (data = io.read(CHUNK_SIZE, buffer ||= String.new))
|
61
63
|
digest.update(data)
|
62
64
|
end
|
63
65
|
digest.base64digest
|
data/lib/tus/errors.rb
CHANGED
data/lib/tus/info.rb
CHANGED
data/lib/tus/input.rb
CHANGED
data/lib/tus/server.rb
CHANGED
data/lib/tus/server/goliath.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
1
|
+
# frozen-string-literal: true
|
1
2
|
require "tus/server"
|
2
3
|
require "goliath"
|
3
4
|
|
5
|
+
warn "Tus::Server::Goliath has been deprecated in favor of goliath-rack_proxy -- https://github.com/janko-m/goliath-rack_proxy"
|
6
|
+
|
4
7
|
class Tus::Server::Goliath < Goliath::API
|
5
8
|
# Called as soon as request headers are parsed.
|
6
9
|
def on_headers(env, headers)
|
data/lib/tus/storage/gridfs.rb
CHANGED
data/lib/tus/storage/s3.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen-string-literal: true
|
1
2
|
require "aws-sdk"
|
2
3
|
|
3
4
|
require "tus/info"
|
@@ -102,10 +103,15 @@ module Tus
|
|
102
103
|
chunk = next_chunk or break
|
103
104
|
end
|
104
105
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
106
|
+
begin
|
107
|
+
jobs.each do |thread, body|
|
108
|
+
info["multipart_parts"] << thread.value
|
109
|
+
bytes_uploaded += body.size
|
110
|
+
body.close
|
111
|
+
end
|
112
|
+
rescue Seahorse::Client::NetworkingError => exception
|
113
|
+
warn "ERROR: #{exception.inspect} occurred during upload"
|
114
|
+
# ignore networking errors and return what client has uploaded so far
|
109
115
|
end
|
110
116
|
|
111
117
|
bytes_uploaded
|
@@ -214,6 +220,7 @@ module Tus
|
|
214
220
|
def copy_parts(objects, multipart_upload)
|
215
221
|
parts = compute_parts(objects, multipart_upload)
|
216
222
|
queue = parts.inject(Queue.new) { |queue, part| queue << part }
|
223
|
+
queue.close
|
217
224
|
|
218
225
|
threads = @thread_count.times.map { copy_part_thread(queue) }
|
219
226
|
|
@@ -236,8 +243,7 @@ module Tus
|
|
236
243
|
Thread.new do
|
237
244
|
begin
|
238
245
|
results = []
|
239
|
-
|
240
|
-
part = queue.deq(true) rescue break
|
246
|
+
while part = queue.pop
|
241
247
|
results << copy_part(part)
|
242
248
|
end
|
243
249
|
results
|
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: 1.
|
4
|
+
version: 1.1.0
|
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-07-
|
11
|
+
date: 2017-07-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: roda
|