s3grep 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/s3grep/search.rb +29 -7
- data/s3grep.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eae78edbf05a9d1e813b713cbf0f6f01ae1fdd1a38c9af08d7e9e313193a2bc0
|
4
|
+
data.tar.gz: 643276478a1368e0e1c715e24d422bf3bbeb9c3752cbea3b996606cce57a6901
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 759897195cc0b5b990e3cc1553af16eb908edba8472cc92236d2cc4a37ee0e98cb5bad1b05b872cc92db6bab11fcdead6a10ebb3e6ea862ef3b28a4cde9f0f94
|
7
|
+
data.tar.gz: 7065e3e8e118917b503565ef6d3cc4bae1dbd0ee33733af8a8b47071c170184e8007b005a3ce0b0631eadec589be8bc1f6e313918c9c57481603fd42086f3854
|
data/lib/s3grep/search.rb
CHANGED
@@ -1,24 +1,32 @@
|
|
1
1
|
require 'aws-sdk-s3'
|
2
|
+
require 'cgi'
|
2
3
|
|
3
4
|
module S3Grep
|
4
5
|
class Search
|
5
6
|
attr_reader :s3_url,
|
6
|
-
:aws_s3_client
|
7
|
+
:aws_s3_client,
|
8
|
+
:compression
|
7
9
|
|
8
|
-
def initialize(s3_url, aws_s3_client)
|
10
|
+
def initialize(s3_url, aws_s3_client, compression = nil)
|
9
11
|
@s3_url = s3_url
|
10
12
|
@aws_s3_client = aws_s3_client
|
13
|
+
@compression = compression
|
11
14
|
end
|
12
15
|
|
13
16
|
def self.search(s3_url, aws_s3_client, regex, &block)
|
14
|
-
new(s3_url, aws_s3_client).search(regex, &block)
|
17
|
+
new(s3_url, aws_s3_client, detect_compression(s3_url)).search(regex, &block)
|
15
18
|
end
|
16
19
|
|
17
|
-
def
|
18
|
-
|
20
|
+
def self.detect_compression(s3_url)
|
21
|
+
return :gzip if s3_url =~ /\.gz$/i
|
22
|
+
return :zip if s3_url =~ /\.zip$/i
|
19
23
|
|
24
|
+
nil
|
25
|
+
end
|
26
|
+
|
27
|
+
def search(regex)
|
20
28
|
line_number = 0
|
21
|
-
|
29
|
+
to_io.each do |line|
|
22
30
|
line_number += 1
|
23
31
|
next unless line.match?(regex)
|
24
32
|
|
@@ -32,9 +40,23 @@ module S3Grep
|
|
32
40
|
aws_s3_client.get_object(
|
33
41
|
{
|
34
42
|
bucket: uri.host,
|
35
|
-
key: uri.path[1..-1]
|
43
|
+
key: CGI.unescape(uri.path[1..-1])
|
36
44
|
}
|
37
45
|
)
|
38
46
|
end
|
47
|
+
|
48
|
+
def to_io
|
49
|
+
body = s3_object.body
|
50
|
+
|
51
|
+
if compression == :gzip
|
52
|
+
Zlib::GzipReader.new(body)
|
53
|
+
elsif compression == :zip
|
54
|
+
require 'rubyzip'
|
55
|
+
zip = Zip::File.open_buffer(body)
|
56
|
+
zip.entries.first.get_input_stream
|
57
|
+
else
|
58
|
+
body
|
59
|
+
end
|
60
|
+
end
|
39
61
|
end
|
40
62
|
end
|
data/s3grep.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: s3grep
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Doug Youch
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-04-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk-s3
|