keyed_archive 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 20bed81f6f133648cf631d3216523aeddbc14eeb
4
+ data.tar.gz: 2d7912ef9102f3ece3b77a64fc872ed1207676c2
5
+ SHA512:
6
+ metadata.gz: 3762da9e73d7512f57c2132b04694a94b8b7b34711253b1b1785b88a5c7835c5d3ea558c32094bb5dde4cc7f68b3ffbd1ea0fb5ff7c20f9cfdc6946f1d292c4d
7
+ data.tar.gz: e68c08996edb3c3e0932c1c5e842de86dd56e263a95ae73ebeba886dd66aea00ec486b428e6878a875b146aed104f61e2cc8254085f3fa062e43dd6f9f914553
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in keyed_archive.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Paul Young
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,102 @@
1
+ # KeyedArchive
2
+
3
+ A Ruby gem for working with files produced by NSKeyedArchiver.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'keyed_archive'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install keyed_archive
18
+
19
+ ## Usage
20
+
21
+ ### Opening a keyed archive
22
+ ```xml
23
+ <?xml version="1.0" encoding="UTF-8"?>
24
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
25
+ <plist version="1.0">
26
+ <dict>
27
+ <key>$version</key>
28
+ <integer>100000</integer>
29
+ <key>$objects</key>
30
+ <array>
31
+ <string>$null</string>
32
+ </array>
33
+ <key>$archiver</key>
34
+ <string>NSKeyedArchiver</string>
35
+ <key>$top</key>
36
+ <dict>
37
+ <key>root</key>
38
+ <dict>
39
+ <key>CF$UID</key>
40
+ <integer>1</integer>
41
+ </dict>
42
+ </dict>
43
+ </dict>
44
+ </plist>
45
+ ```
46
+
47
+ ```ruby
48
+ require 'keyed_archive'
49
+
50
+ filename = "path/to/file.plist"
51
+ keyed_archive = KeyedArchive.new("path/to/file.plist")
52
+ keyed_archive.archiver # "NSKeyedArchiver"
53
+ keyed_archive.objects # ["$null"]
54
+ keyed_archive.top # {"root"=>{"CF$UID"=>1}}
55
+ keyed_archive.version # 100000
56
+ ```
57
+
58
+ ### Unpacking keyed archive objects
59
+ ```xml
60
+ <?xml version="1.0" encoding="UTF-8"?>
61
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
62
+ <plist version="1.0">
63
+ <dict>
64
+ <key>$version</key>
65
+ <integer>100000</integer>
66
+ <key>$objects</key>
67
+ <array>
68
+ <string>$null</string>
69
+ <dict>
70
+ <key>key</key>
71
+ <string>value</string>
72
+ </dict>
73
+ </array>
74
+ <key>$archiver</key>
75
+ <string>NSKeyedArchiver</string>
76
+ <key>$top</key>
77
+ <dict>
78
+ <key>root</key>
79
+ <dict>
80
+ <key>CF$UID</key>
81
+ <integer>1</integer>
82
+ </dict>
83
+ </dict>
84
+ </dict>
85
+ </plist>
86
+ ```
87
+
88
+ ```ruby
89
+ require 'keyed_archive'
90
+
91
+ keyed_archive = KeyedArchive.new("path/to/file.plist")
92
+ keyed_archive.objects # ["$null", "value", {"reference"=>{"CF$UID"=>3}}, {"key"=>{"CF$UID"=>1}}]
93
+ keyed_archive.unpacked_objects() # ["$null", {"key"=>"value"}]
94
+ ```
95
+
96
+ ## Contributing
97
+
98
+ 1. Fork it ( http://github.com/<my-github-username>/keyed_archive/fork )
99
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
100
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
101
+ 4. Push to the branch (`git push origin my-new-feature`)
102
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rspec/core'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec) do |spec|
7
+ spec.pattern = FileList["spec/**/*_spec.rb"]
8
+ end
9
+
10
+ task :default => :spec
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'keyed_archive/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "keyed_archive"
8
+ spec.version = KeyedArchive::VERSION
9
+ spec.authors = ["Paul Young"]
10
+ spec.email = ["paulyoungonline@gmail.com"]
11
+ spec.summary = %q{A Ruby gem for working with files produced by NSKeyedArchiver.}
12
+ spec.homepage = "https://github.com/paulyoung/keyed_archive"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency "CFPropertyList", "~> 2.2.7"
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.5"
23
+ spec.add_development_dependency "rake"
24
+ spec.add_development_dependency "rspec", "~> 2.14.1"
25
+ end
@@ -0,0 +1,18 @@
1
+ require 'cfpropertylist'
2
+
3
+ require "keyed_archive/unpacked_objects"
4
+ require "keyed_archive/version"
5
+
6
+ class KeyedArchive
7
+ attr_accessor :archiver, :objects, :top, :version
8
+
9
+ def initialize(file)
10
+ plist = CFPropertyList::List.new(:file => file)
11
+ data = CFPropertyList.native_types(plist.value)
12
+
13
+ @archiver = data['$archiver']
14
+ @objects = data['$objects']
15
+ @top = data['$top']
16
+ @version = data['$version']
17
+ end
18
+ end
@@ -0,0 +1,31 @@
1
+ class KeyedArchive
2
+ def unpacked_objects
3
+ objects = @objects.clone
4
+ unpacked_objects = []
5
+
6
+ objects.each_with_index do |object, index|
7
+ if object.is_a? Hash
8
+ object.each_pair do |key, value|
9
+ if value.is_a? Hash
10
+ uid = value['CF$UID']
11
+
12
+ if uid
13
+ new_object = {}
14
+ new_object[key] = @objects[uid]
15
+ objects.push new_object
16
+ unpacked_objects.delete_at(index - 1)
17
+ end
18
+ else
19
+ new_object = {}
20
+ new_object[key] = value
21
+ unpacked_objects.push new_object
22
+ end
23
+ end
24
+ else
25
+ unpacked_objects.push object
26
+ end
27
+ end
28
+
29
+ return unpacked_objects
30
+ end
31
+ end
@@ -0,0 +1,3 @@
1
+ class KeyedArchive
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,37 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>$version</key>
6
+ <integer>100000</integer>
7
+ <key>$objects</key>
8
+ <array>
9
+ <string>$null</string>
10
+ <string>value</string>
11
+ <dict>
12
+ <key>reference</key>
13
+ <dict>
14
+ <key>CF$UID</key>
15
+ <integer>3</integer>
16
+ </dict>
17
+ </dict>
18
+ <dict>
19
+ <key>key</key>
20
+ <dict>
21
+ <key>CF$UID</key>
22
+ <integer>1</integer>
23
+ </dict>
24
+ </dict>
25
+ </array>
26
+ <key>$archiver</key>
27
+ <string>NSKeyedArchiver</string>
28
+ <key>$top</key>
29
+ <dict>
30
+ <key>root</key>
31
+ <dict>
32
+ <key>CF$UID</key>
33
+ <integer>1</integer>
34
+ </dict>
35
+ </dict>
36
+ </dict>
37
+ </plist>
@@ -0,0 +1,26 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>$version</key>
6
+ <integer>100000</integer>
7
+ <key>$objects</key>
8
+ <array>
9
+ <string>$null</string>
10
+ <dict>
11
+ <key>key</key>
12
+ <string>value</string>
13
+ </dict>
14
+ </array>
15
+ <key>$archiver</key>
16
+ <string>NSKeyedArchiver</string>
17
+ <key>$top</key>
18
+ <dict>
19
+ <key>root</key>
20
+ <dict>
21
+ <key>CF$UID</key>
22
+ <integer>1</integer>
23
+ </dict>
24
+ </dict>
25
+ </dict>
26
+ </plist>
@@ -0,0 +1,22 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>$version</key>
6
+ <integer>100000</integer>
7
+ <key>$objects</key>
8
+ <array>
9
+ <string>$null</string>
10
+ </array>
11
+ <key>$archiver</key>
12
+ <string>NSKeyedArchiver</string>
13
+ <key>$top</key>
14
+ <dict>
15
+ <key>root</key>
16
+ <dict>
17
+ <key>CF$UID</key>
18
+ <integer>1</integer>
19
+ </dict>
20
+ </dict>
21
+ </dict>
22
+ </plist>
@@ -0,0 +1,30 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>$version</key>
6
+ <integer>100000</integer>
7
+ <key>$objects</key>
8
+ <array>
9
+ <string>$null</string>
10
+ <string>value</string>
11
+ <dict>
12
+ <key>key</key>
13
+ <dict>
14
+ <key>CF$UID</key>
15
+ <integer>1</integer>
16
+ </dict>
17
+ </dict>
18
+ </array>
19
+ <key>$archiver</key>
20
+ <string>NSKeyedArchiver</string>
21
+ <key>$top</key>
22
+ <dict>
23
+ <key>root</key>
24
+ <dict>
25
+ <key>CF$UID</key>
26
+ <integer>1</integer>
27
+ </dict>
28
+ </dict>
29
+ </dict>
30
+ </plist>
@@ -0,0 +1,26 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>$version</key>
6
+ <integer>100000</integer>
7
+ <key>$objects</key>
8
+ <array>
9
+ <string>$null</string>
10
+ <dict>
11
+ <key>key</key>
12
+ <string>value</string>
13
+ </dict>
14
+ </array>
15
+ <key>$archiver</key>
16
+ <string>NSKeyedArchiver</string>
17
+ <key>$top</key>
18
+ <dict>
19
+ <key>root</key>
20
+ <dict>
21
+ <key>CF$UID</key>
22
+ <integer>1</integer>
23
+ </dict>
24
+ </dict>
25
+ </dict>
26
+ </plist>
@@ -0,0 +1,30 @@
1
+ require "keyed_archive"
2
+
3
+ describe KeyedArchive, "#initialize" do
4
+ let(:filename) { 'spec/fixtures/empty.plist' }
5
+
6
+ it "should create an instance" do
7
+ keyed_archive = KeyedArchive.new(filename)
8
+ expect(keyed_archive).to be_instance_of(KeyedArchive)
9
+ end
10
+
11
+ it "should set the archiver" do
12
+ keyed_archive = KeyedArchive.new(filename)
13
+ expect(keyed_archive.archiver).to be_a(String)
14
+ end
15
+
16
+ it "should set the objects" do
17
+ keyed_archive = KeyedArchive.new(filename)
18
+ expect(keyed_archive.objects).to be_an(Array)
19
+ end
20
+
21
+ it "should set the top" do
22
+ keyed_archive = KeyedArchive.new(filename)
23
+ expect(keyed_archive.top).to be_a(Hash)
24
+ end
25
+
26
+ it "should set the version" do
27
+ keyed_archive = KeyedArchive.new(filename)
28
+ expect(keyed_archive.version).to be_an(Integer)
29
+ end
30
+ end
@@ -0,0 +1,27 @@
1
+ require "keyed_archive/unpacked_objects"
2
+
3
+ shared_examples "unpack" do
4
+ it "should unpack objects" do
5
+ keyed_archive = KeyedArchive.new(filename)
6
+ unpacked_objects = keyed_archive.unpacked_objects()
7
+ fixture_archive = KeyedArchive.new(fixture)
8
+ expect(unpacked_objects).to eq(fixture_archive.objects)
9
+ end
10
+ end
11
+
12
+ describe KeyedArchive, "#unpack" do
13
+ context "single reference" do
14
+ it_behaves_like "unpack" do
15
+ let(:filename) { "spec/fixtures/single_object_reference.plist" }
16
+ let(:fixture) { "spec/fixtures/single_object_reference_unpacked.plist" }
17
+ end
18
+ end
19
+
20
+ context "double reference" do
21
+ it_behaves_like "unpack" do
22
+ let(:filename) { "spec/fixtures/double_object_reference.plist" }
23
+ let(:fixture) { "spec/fixtures/double_object_reference_unpacked.plist" }
24
+ end
25
+ end
26
+ end
27
+
metadata ADDED
@@ -0,0 +1,124 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: keyed_archive
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Paul Young
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: CFPropertyList
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 2.2.7
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 2.2.7
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.5'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 2.14.1
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 2.14.1
69
+ description:
70
+ email:
71
+ - paulyoungonline@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - keyed_archive.gemspec
83
+ - lib/keyed_archive.rb
84
+ - lib/keyed_archive/unpacked_objects.rb
85
+ - lib/keyed_archive/version.rb
86
+ - spec/fixtures/double_object_reference.plist
87
+ - spec/fixtures/double_object_reference_unpacked.plist
88
+ - spec/fixtures/empty.plist
89
+ - spec/fixtures/single_object_reference.plist
90
+ - spec/fixtures/single_object_reference_unpacked.plist
91
+ - spec/keyed_archive_spec.rb
92
+ - spec/unpacked_objects_spec.rb
93
+ homepage: https://github.com/paulyoung/keyed_archive
94
+ licenses:
95
+ - MIT
96
+ metadata: {}
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubyforge_project:
113
+ rubygems_version: 2.2.2
114
+ signing_key:
115
+ specification_version: 4
116
+ summary: A Ruby gem for working with files produced by NSKeyedArchiver.
117
+ test_files:
118
+ - spec/fixtures/double_object_reference.plist
119
+ - spec/fixtures/double_object_reference_unpacked.plist
120
+ - spec/fixtures/empty.plist
121
+ - spec/fixtures/single_object_reference.plist
122
+ - spec/fixtures/single_object_reference_unpacked.plist
123
+ - spec/keyed_archive_spec.rb
124
+ - spec/unpacked_objects_spec.rb