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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4970687c1cfd81a01844c3626f4ee8e879410772
4
- data.tar.gz: 017e147d7dbf79a40fb9ab1ada4a9c87b4490f81
3
+ metadata.gz: 0e7ec2a89ccbb20c13484b06734c5a8892eef8c1
4
+ data.tar.gz: 8d00f4e4f025bd5292979d2b33582a13aca157eb
5
5
  SHA512:
6
- metadata.gz: 7b937ef67a26f46eeaa45e241bf593684ef99420d8ff41007bcf734130b891733f71a096c61a00c02bc805fbcf4aa1932260f4c85f5c4ac09fb097a8f53d4ef7
7
- data.tar.gz: 24ee3bc3aab8dc3b4bf427dc5a65477efdf8b2dbb03edefeb8f23ee77ee0adf31c5e3d022b26223a36c0d2f69125177c958cae712a6f18feff7cde5e6a76d51d
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] (and `concatenation-unfinished`)
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 = nil
51
- crc = Zlib.crc32(io.read(16*1024, buffer ||= "").to_s, crc) until io.eof?
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 ||= "").to_s) until io.eof?
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
@@ -16,7 +16,7 @@ module Tus
16
16
  "creation", "creation-defer-length",
17
17
  "termination",
18
18
  "expiration",
19
- "concatenation", "concatenation-unfinished",
19
+ "concatenation",
20
20
  "checksum",
21
21
  ]
22
22
  SUPPORTED_CHECKSUM_ALGORITHMS = %w[sha1 sha256 sha384 sha512 md5 crc32]
@@ -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, buffer ||= "") or break
84
+ chunk = file.read([16*1024, remaining_length].min) or break
85
85
  remaining_length -= chunk.bytesize
86
86
  yielder << chunk
87
87
  end
@@ -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 = client
15
- @prefix = 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
 
@@ -67,15 +67,15 @@ module Tus
67
67
  raise error
68
68
  end
69
69
 
70
- def patch_file(uid, io, info = {})
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(io)
76
+ md5 = Tus::Checksum.new("md5").generate(input)
77
77
 
78
- response = multipart_part.upload(body: io, content_md5: md5)
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 = Enumerator.new do |yielder|
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
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |gem|
2
2
  gem.name = "tus-server"
3
- gem.version = "0.10.0"
3
+ gem.version = "0.10.1"
4
4
 
5
5
  gem.required_ruby_version = ">= 2.1"
6
6
 
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.0
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-03-27 00:00:00.000000000 Z
11
+ date: 2017-04-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: roda