gcs_stream_upload 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +82 -0
- data/README.md +64 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/gcs_stream_upload.gemspec +29 -0
- data/lib/gcs_stream_upload.rb +51 -0
- data/lib/gcs_stream_upload/version.rb +3 -0
- metadata +126 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 053daafd743ac2c2a14310f7b15a5875f475431c4c94578ac8968a5878d4cbb8
|
4
|
+
data.tar.gz: 21a7762b275ee5e9f168e9df7260f42dc8b24c4dc248d5d046730b4a267ea13b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a9c657ddf67e58a1b7dd6b9e3a07c09cbe2b1c18cd1a5ae1effc266bbb3ace2accacf993be9261ff05a580b6857a12fe2b8b66cc8a985188e69c1143394df342
|
7
|
+
data.tar.gz: 66de9652603b1118ea1cfff16d7164c6ea9d06a7042c65c91dde5cbfd98a4d0e39ed0c2edcd2de372286ccf13917ba6fc73ded5fd1054fe5e28fc3c4d16725bc
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at fonsan@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
GEM
|
2
|
+
remote: https://rubygems.org/
|
3
|
+
specs:
|
4
|
+
addressable (2.5.2)
|
5
|
+
public_suffix (>= 2.0.2, < 4.0)
|
6
|
+
declarative (0.0.10)
|
7
|
+
declarative-option (0.1.0)
|
8
|
+
diff-lcs (1.3)
|
9
|
+
digest-crc (0.4.1)
|
10
|
+
faraday (0.15.3)
|
11
|
+
multipart-post (>= 1.2, < 3)
|
12
|
+
google-api-client (0.25.0)
|
13
|
+
addressable (~> 2.5, >= 2.5.1)
|
14
|
+
googleauth (>= 0.5, < 0.7.0)
|
15
|
+
httpclient (>= 2.8.1, < 3.0)
|
16
|
+
mime-types (~> 3.0)
|
17
|
+
representable (~> 3.0)
|
18
|
+
retriable (>= 2.0, < 4.0)
|
19
|
+
signet (~> 0.10)
|
20
|
+
google-cloud-core (1.2.7)
|
21
|
+
google-cloud-env (~> 1.0)
|
22
|
+
google-cloud-env (1.0.5)
|
23
|
+
faraday (~> 0.11)
|
24
|
+
google-cloud-storage (1.15.0)
|
25
|
+
digest-crc (~> 0.4)
|
26
|
+
google-api-client (~> 0.23)
|
27
|
+
google-cloud-core (~> 1.2)
|
28
|
+
googleauth (~> 0.6.2)
|
29
|
+
googleauth (0.6.6)
|
30
|
+
faraday (~> 0.12)
|
31
|
+
jwt (>= 1.4, < 3.0)
|
32
|
+
memoist (~> 0.12)
|
33
|
+
multi_json (~> 1.11)
|
34
|
+
os (>= 0.9, < 2.0)
|
35
|
+
signet (~> 0.7)
|
36
|
+
httpclient (2.8.3)
|
37
|
+
jwt (2.1.0)
|
38
|
+
memoist (0.16.0)
|
39
|
+
mime-types (3.2.2)
|
40
|
+
mime-types-data (~> 3.2015)
|
41
|
+
mime-types-data (3.2018.0812)
|
42
|
+
multi_json (1.13.1)
|
43
|
+
multipart-post (2.0.0)
|
44
|
+
os (1.0.0)
|
45
|
+
public_suffix (3.0.3)
|
46
|
+
rake (12.3.1)
|
47
|
+
representable (3.0.4)
|
48
|
+
declarative (< 0.1.0)
|
49
|
+
declarative-option (< 0.2.0)
|
50
|
+
uber (< 0.2.0)
|
51
|
+
retriable (3.1.2)
|
52
|
+
rspec (3.8.0)
|
53
|
+
rspec-core (~> 3.8.0)
|
54
|
+
rspec-expectations (~> 3.8.0)
|
55
|
+
rspec-mocks (~> 3.8.0)
|
56
|
+
rspec-core (3.8.0)
|
57
|
+
rspec-support (~> 3.8.0)
|
58
|
+
rspec-expectations (3.8.2)
|
59
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
60
|
+
rspec-support (~> 3.8.0)
|
61
|
+
rspec-mocks (3.8.0)
|
62
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
63
|
+
rspec-support (~> 3.8.0)
|
64
|
+
rspec-support (3.8.0)
|
65
|
+
signet (0.10.0)
|
66
|
+
addressable (~> 2.3)
|
67
|
+
faraday (~> 0.9)
|
68
|
+
jwt (>= 1.5, < 3.0)
|
69
|
+
multi_json (~> 1.10)
|
70
|
+
uber (0.1.0)
|
71
|
+
|
72
|
+
PLATFORMS
|
73
|
+
ruby
|
74
|
+
|
75
|
+
DEPENDENCIES
|
76
|
+
google-api-client (= 0.25.0)
|
77
|
+
google-cloud-storage (= 1.15.0)
|
78
|
+
rake
|
79
|
+
rspec
|
80
|
+
|
81
|
+
BUNDLED WITH
|
82
|
+
1.16.2
|
data/README.md
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
# GCSStreamUpload
|
2
|
+
|
3
|
+
A simple wrapper on top of `google_cloud_storage` allowing for streaming uploads. It uses the underlying resumable uploads provided in the json api.
|
4
|
+
|
5
|
+
Unfortunately the `UPLOAD_CONTENT_LENGTH` header is hardcoded to be set in `google-api-client` and the following monkey patch is necessary and is included:
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
if upload_io.respond_to?(:size)
|
9
|
+
request_header[UPLOAD_CONTENT_LENGTH] = upload_io.size.to_s
|
10
|
+
end
|
11
|
+
```
|
12
|
+
|
13
|
+
## Installation
|
14
|
+
|
15
|
+
Add this line to your application's Gemfile:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
gem 'gcs_stream_upload'
|
19
|
+
```
|
20
|
+
|
21
|
+
And then execute:
|
22
|
+
|
23
|
+
$ bundle
|
24
|
+
|
25
|
+
Or install it yourself as:
|
26
|
+
|
27
|
+
$ gem install gcs_stream_upload
|
28
|
+
|
29
|
+
## Usage
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
require 'gcs_stream_upload'
|
33
|
+
|
34
|
+
storage = Google::Cloud::Storage.new(timeout: 5 * 60)
|
35
|
+
bucket = storage.bucket('bucket')
|
36
|
+
gcs_stream_upload = GCSStreamUpload.new(bucket)
|
37
|
+
|
38
|
+
gcs_stream_upload.upload('object') do |io|
|
39
|
+
IO.copy_stream(IO.popen('yes | head -n 10'), io)
|
40
|
+
end
|
41
|
+
# => Written "y\n" * 10
|
42
|
+
|
43
|
+
|
44
|
+
gcs_stream_upload.upload('object') do |io|
|
45
|
+
io << 'data'
|
46
|
+
io << 'dat2'
|
47
|
+
end
|
48
|
+
# => Written "datadat2"
|
49
|
+
|
50
|
+
```
|
51
|
+
|
52
|
+
## Development
|
53
|
+
|
54
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
55
|
+
|
56
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
57
|
+
|
58
|
+
## Contributing
|
59
|
+
|
60
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/Fonsan/gcs_stream_upload. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
61
|
+
|
62
|
+
## Code of Conduct
|
63
|
+
|
64
|
+
Everyone interacting in the GcsStreamUpload project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/Fonsan/gcs_stream_upload/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$: << File.expand_path('../../lib', __FILE__)
|
3
|
+
require "bundler/setup"
|
4
|
+
require "gcs_stream_upload"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "gcs_stream_upload/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "gcs_stream_upload"
|
8
|
+
spec.version = GCSStreamUpload::VERSION
|
9
|
+
spec.authors = ["Fonsan"]
|
10
|
+
spec.email = ["fonsan@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Google Cloud Storage streaming uploader}
|
13
|
+
spec.description = %q{Google Cloud Storage streaming uploader}
|
14
|
+
|
15
|
+
# Specify which files should be added to the gem when it is released.
|
16
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
17
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
18
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
19
|
+
end
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_dependency "google-cloud-storage", "= 1.15.0"
|
25
|
+
spec.add_dependency 'google-api-client', '= 0.25.0'
|
26
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
27
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
28
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
29
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require "gcs_stream_upload/version"
|
2
|
+
require "google/cloud/storage"
|
3
|
+
require "delegate"
|
4
|
+
|
5
|
+
class ::Google::Apis::Core::ResumableUploadCommand
|
6
|
+
def send_start_command(client)
|
7
|
+
logger.debug { sprintf('Sending upload start command to %s', url) }
|
8
|
+
|
9
|
+
request_header = header.dup
|
10
|
+
apply_request_options(request_header)
|
11
|
+
request_header[UPLOAD_PROTOCOL_HEADER] = RESUMABLE
|
12
|
+
request_header[UPLOAD_COMMAND_HEADER] = START_COMMAND
|
13
|
+
if upload_io.respond_to?(:size)
|
14
|
+
request_header[UPLOAD_CONTENT_LENGTH] = upload_io.size.to_s
|
15
|
+
end
|
16
|
+
request_header[UPLOAD_CONTENT_TYPE_HEADER] = upload_content_type
|
17
|
+
|
18
|
+
client.request(method.to_s.upcase,
|
19
|
+
url.to_s, query: nil,
|
20
|
+
body: body,
|
21
|
+
header: request_header,
|
22
|
+
follow_redirect: true)
|
23
|
+
rescue => e
|
24
|
+
raise Google::Apis::ServerError, e.message
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
class GCSStreamUpload
|
29
|
+
def initialize(bucket)
|
30
|
+
@bucket = bucket
|
31
|
+
end
|
32
|
+
|
33
|
+
def upload(*args)
|
34
|
+
read_pipe, write_pipe = IO.pipe
|
35
|
+
def read_pipe.pos
|
36
|
+
0
|
37
|
+
end
|
38
|
+
def read_pipe.pos=(value)
|
39
|
+
end
|
40
|
+
thread = Thread.start do
|
41
|
+
yield(write_pipe)
|
42
|
+
rescue StandardError => e
|
43
|
+
e
|
44
|
+
ensure
|
45
|
+
write_pipe.close_write
|
46
|
+
end
|
47
|
+
@bucket.create_file(read_pipe, *args)
|
48
|
+
result = thread.value
|
49
|
+
raise result if result.is_a?(StandardError)
|
50
|
+
end
|
51
|
+
end
|
metadata
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gcs_stream_upload
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Fonsan
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-11-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: google-cloud-storage
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.15.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.15.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: google-api-client
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.25.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.25.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.16'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.16'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.0'
|
83
|
+
description: Google Cloud Storage streaming uploader
|
84
|
+
email:
|
85
|
+
- fonsan@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".rspec"
|
92
|
+
- ".travis.yml"
|
93
|
+
- CODE_OF_CONDUCT.md
|
94
|
+
- Gemfile
|
95
|
+
- Gemfile.lock
|
96
|
+
- README.md
|
97
|
+
- Rakefile
|
98
|
+
- bin/console
|
99
|
+
- bin/setup
|
100
|
+
- gcs_stream_upload.gemspec
|
101
|
+
- lib/gcs_stream_upload.rb
|
102
|
+
- lib/gcs_stream_upload/version.rb
|
103
|
+
homepage:
|
104
|
+
licenses: []
|
105
|
+
metadata: {}
|
106
|
+
post_install_message:
|
107
|
+
rdoc_options: []
|
108
|
+
require_paths:
|
109
|
+
- lib
|
110
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
requirements: []
|
121
|
+
rubyforge_project:
|
122
|
+
rubygems_version: 2.7.7
|
123
|
+
signing_key:
|
124
|
+
specification_version: 4
|
125
|
+
summary: Google Cloud Storage streaming uploader
|
126
|
+
test_files: []
|