sqlar 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 89ca8fc2548d201cf7efd094a251cbcd027a95c7
4
+ data.tar.gz: 9fd3b89b6d73d626192f4893f94a9795592aff65
5
+ SHA512:
6
+ metadata.gz: a3141ba533e8e6492396d91c8ef75e8e6b6a4919548a9b1a1f161b5ff9824b483c19f3e5552df650185ee8495eb9e4b8e9cab31411214ba6e4cb7441ec2375c5
7
+ data.tar.gz: 07ee377b016f204bd60ed2f7844d1323f7ba3a0b5e744762acb7e2108fa2e6970e9a54e5c22ed8ea9a34027a5d7f72e85df1946b30077ecd5e1e380261fefd35
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.12.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in sqlar.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Jamie Little
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,59 @@
1
+ # Sqlar
2
+
3
+ This is a Ruby Gem for createing [SQLite Archiver](https://www.sqlite.org/sqlar) compatiable files.
4
+
5
+ SQLite Archiver is a tool for embedding files in a SQLite database.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'sqlar'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install sqlar
22
+
23
+ ## Usage
24
+
25
+ Inserting a file into a sqlar:
26
+
27
+ ```ruby
28
+ sqlar = Sqlar::Sqlar.new("test.sqlite3")
29
+ blob = sqlar.get_blob("test/test.jpg")
30
+ sqlar.insert(blob)
31
+ ```
32
+ Extracting files from a sqlar:
33
+ ```ruby
34
+ sqlar = Sqlar::Sqlar.new("test/existing_test.sqlite")
35
+ sqlar.extract_all()
36
+ ```
37
+
38
+ Extracting a specific file from a sqlar:
39
+
40
+ ```ruby
41
+ sqlar = Sqlar::Sqlar.new("test/existing_test.sqlite")
42
+ sqlar.extract('Users/jlittle/Desktop/0-0-0.jpg')
43
+ ```
44
+
45
+ ## Development
46
+
47
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
48
+
49
+ 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).
50
+
51
+ ## Contributing
52
+
53
+ Bug reports and pull requests are welcome on GitHub at https://github.com/little9/sqlar.
54
+
55
+
56
+ ## License
57
+
58
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
59
+
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "sqlar"
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
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/lib/sqlar.rb ADDED
@@ -0,0 +1,105 @@
1
+ require "sqlar/version"
2
+ require 'sqlite3'
3
+ require 'pathname'
4
+ require 'sqlar_blob'
5
+ require 'fileutils'
6
+
7
+ module Sqlar
8
+ class Sqlar
9
+ attr_accessor :files
10
+
11
+ def initialize(db_name)
12
+ @db_name = db_name
13
+
14
+ begin
15
+ SQLite3::Database.open(@db_name) do |db|
16
+ db.results_as_hash = true
17
+ rows = db.execute("SELECT * FROM sqlar")
18
+ if rows.nil?
19
+ create_sqlar()
20
+ else
21
+ @files = rows
22
+ end
23
+ end
24
+ rescue
25
+ SQLite3::Database.new(@db_name)
26
+ create_sqlar()
27
+ end
28
+ end
29
+
30
+ def create_sqlar()
31
+ SQLite3::Database.open(@db_name) do |db|
32
+ db.execute("CREATE TABLE sqlar(
33
+ name TEXT PRIMARY KEY,
34
+ mode INT,
35
+ mtime INT,
36
+ sz INT,
37
+ data BLOB
38
+ )" )
39
+ end
40
+ end
41
+
42
+ def insert(blob)
43
+ SQLite3::Database.open(@db_name) do |db|
44
+ blob.name[0] = ''
45
+ db.execute("INSERT INTO sqlar (name, mode, mtime, sz,data) VALUES (?,?,?,?,?)",blob.name,blob.mode,blob.mtime,blob.sz,blob.data)
46
+ end
47
+ end
48
+
49
+ def extract(name)
50
+ SQLite3::Database.open(@db_name) do |db|
51
+ blob = db.get_first_value("SELECT data FROM sqlar WHERE name = ?",name)
52
+ path = name.gsub(File.basename(name), '')
53
+ FileUtils.makedirs(path)
54
+ f = File.new(path+File.basename(name), "wb")
55
+ f.write(blob)
56
+ end
57
+ end
58
+
59
+ def extract_all()
60
+ SQLite3::Database.open(@db_name) do |db|
61
+ db.results_as_hash = true
62
+ db.execute("SELECT * FROM sqlar") do |rows|
63
+ blob = rows['data']
64
+ path = rows['name'].gsub(File.basename(rows['name']), '')
65
+ begin
66
+ FileUtils.makedirs(path)
67
+ f = File.new(path+File.basename(rows['name']), "wb")
68
+ f.chmod(rows['mode'])
69
+ f.write(blob)
70
+ File.utime(rows['mtime'], rows['mtime'],File.absolute_path(f.path))
71
+ rescue SystemCallError => e
72
+ puts e
73
+ ensure
74
+ f.close if f
75
+ end
76
+ end
77
+ end
78
+ end
79
+
80
+ def get_blob(file)
81
+ begin
82
+ file = File.open file, "rb"
83
+ stat = file.lstat
84
+ blob = file.read
85
+ sqlar_blob = SqlarBlob.new
86
+ sqlar_blob.name = File.absolute_path(file.path)
87
+ sqlar_blob.mode = stat.mode
88
+ sqlar_blob.mtime = stat.mtime.to_i
89
+ sqlar_blob.sz = file.size
90
+ sqlar_blob.data = SQLite3::Blob.new blob
91
+ rescue SystemCallError => e
92
+ puts e
93
+ ensure
94
+ file.close if file
95
+ end
96
+ return sqlar_blob
97
+ end
98
+ end
99
+ end
100
+
101
+
102
+
103
+
104
+
105
+
@@ -0,0 +1,3 @@
1
+ module Sqlar
2
+ VERSION = "0.1.0"
3
+ end
data/lib/sqlar_blob.rb ADDED
@@ -0,0 +1,9 @@
1
+ module Sqlar
2
+ class SqlarBlob
3
+ attr_accessor :name
4
+ attr_accessor :mode
5
+ attr_accessor :mtime
6
+ attr_accessor :sz
7
+ attr_accessor :data
8
+ end
9
+ end
data/sqlar.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'sqlar/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "sqlar"
8
+ spec.version = Sqlar::VERSION
9
+ spec.authors = ["Jamie Little"]
10
+ spec.email = ["j.little@miami.edu"]
11
+
12
+ spec.summary = "A ruby gem that duplicates the funcationality of the SQLite Archiver"
13
+ spec.description = "A ruby gem that duplicates the funcationality of the SQLite Archiver"
14
+ spec.homepage = "https://github.com/little9/sqlar"
15
+ spec.license = "MIT"
16
+
17
+
18
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.12"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "minitest", "~> 5.0"
26
+ spec.add_runtime_dependency "sqlite3"
27
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sqlar
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jamie Little
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-10-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: sqlite3
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: A ruby gem that duplicates the funcationality of the SQLite Archiver
70
+ email:
71
+ - j.little@miami.edu
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".travis.yml"
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - bin/console
83
+ - bin/setup
84
+ - lib/sqlar.rb
85
+ - lib/sqlar/version.rb
86
+ - lib/sqlar_blob.rb
87
+ - sqlar.gemspec
88
+ homepage: https://github.com/little9/sqlar
89
+ licenses:
90
+ - MIT
91
+ metadata: {}
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 2.5.1
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: A ruby gem that duplicates the funcationality of the SQLite Archiver
112
+ test_files: []