CFPropertyList 2.3.5 → 3.0.3

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
- SHA1:
3
- metadata.gz: 74e0407ecce8171dfa845b93f5f55e1cd7d386a3
4
- data.tar.gz: d3d8e956ad24476ee83293c9f4d25fa23b7f2947
2
+ SHA256:
3
+ metadata.gz: b3293e20bb67a67db1ace3430acbd0d0662770ea7a80a65440f35ac5cfd57b1c
4
+ data.tar.gz: 8713fd11f1a07dd2e4df46fef316dd5b14ec8080ce88540135079367c23d6c34
5
5
  SHA512:
6
- metadata.gz: 96bc102584b4a4745bcfaa403667644fff60e8be9b2ad9224c454f6b977b236f16156863cc48d20b8aa4cffc0f9f0e4bbea5c05fc7f06450afb49cb37f4aaede
7
- data.tar.gz: 9f36e44475f5b7a48d957e54b35ed99a821c3df6ead60598c4fd8a7637bbbb1b9bfa8d5a7a438456ae814696ed52a438dbf94151cf2b29974995716c78a7189a
6
+ metadata.gz: bdc8bbf4e1207a1c540d4583e05c715e6b881aa0ae60f3d97a6485280ce5f3d20aba63894b178e03203acbf8dbd09a93ff336c12ef1840857b12b291009c29f5
7
+ data.tar.gz: 5d9c710d512e6a7b3d177042f2ebd717b46dab16c1f37fc3dc539ce588d8d12b1438e71e9dac4408555c9ec1eb9903ea482565d8f846774e935615b913a89dea
@@ -0,0 +1,79 @@
1
+ CFPropertyList implementation
2
+ class to read, manipulate and write both XML and binary property list
3
+ files (plist(5)) as defined by Apple. Have a look at CFPropertyList::List
4
+ for more documentation.
5
+
6
+ # Caution!
7
+
8
+ In version 3.0.0 we dropped Ruby 1.8 compatibility. If you are using
9
+ Ruby 1.8 consider to update Ruby; if you can't upgrade, don't upgrade
10
+ CFPropertyList.
11
+
12
+ # Installation
13
+
14
+ You could either use ruby gems and install it via
15
+
16
+ ```bash
17
+ gem install CFPropertyList
18
+ ```
19
+
20
+ or you could clone this repository and place it somewhere in your load path.
21
+
22
+ Example:
23
+ ```ruby
24
+ require 'cfpropertylist'
25
+ ```
26
+
27
+ If you're using Rails, you can add it into your Gemfile
28
+
29
+ ```ruby
30
+ gem 'CFPropertyList'
31
+ ```
32
+
33
+ # Usage
34
+
35
+ ## create a arbitrary data structure of basic data types
36
+
37
+ ```ruby
38
+ data = {
39
+ 'name' => 'John Doe',
40
+ 'missing' => true,
41
+ 'last_seen' => Time.now,
42
+ 'friends' => ['Jane Doe','Julian Doe'],
43
+ 'likes' => {
44
+ 'me' => false
45
+ }
46
+ }
47
+ ```
48
+
49
+ ## create CFPropertyList::List object
50
+
51
+ ```ruby
52
+ plist = CFPropertyList::List.new
53
+ ```
54
+
55
+ ## call CFPropertyList.guess() to create corresponding CFType values
56
+
57
+ ```ruby
58
+ plist.value = CFPropertyList.guess(data)
59
+ ```
60
+
61
+ ## write plist to file
62
+ ```ruby
63
+ plist.save("example.plist", CFPropertyList::List::FORMAT_BINARY)
64
+ ```
65
+
66
+ ## … later, read it again
67
+ ```ruby
68
+ plist = CFPropertyList::List.new(:file => "example.plist")
69
+ data = CFPropertyList.native_types(plist.value)
70
+ ```
71
+
72
+ # Author and license
73
+
74
+ **Author:** Christian Kruse (mailto:cjk@wwwtech.de)
75
+
76
+ **Copyright:** Copyright (c) 2010
77
+
78
+ **License:** MIT License
79
+
@@ -41,4 +41,3 @@ or you could clone this repository and place it somewhere in your load path.
41
41
  Author:: Christian Kruse (mailto:cjk@wwwtech.de)
42
42
  Copyright:: Copyright (c) 2010
43
43
  License:: MIT License
44
-
@@ -123,8 +123,8 @@ module CFPropertyList
123
123
 
124
124
  # read a binary int value
125
125
  def read_binary_int(fname,fd,length)
126
- if length > 3
127
- raise CFFormatError.new("Integer greater than 8 bytes: #{length}")
126
+ if length > 4
127
+ raise CFFormatError.new("Integer greater than 16 bytes: #{length}")
128
128
  end
129
129
 
130
130
  nbytes = 1 << length
@@ -136,17 +136,12 @@ module CFPropertyList
136
136
  when 0 then buff.unpack("C")[0]
137
137
  when 1 then buff.unpack("n")[0]
138
138
  when 2 then buff.unpack("N")[0]
139
- when 3
140
- hiword,loword = buff.unpack("NN")
141
- if (hiword & 0x80000000) != 0
142
- # 8 byte integers are always signed, and are negative when bit 63 is
143
- # set. Decoding into either a Fixnum or Bignum is tricky, however,
144
- # because the size of a Fixnum varies among systems, and Ruby
145
- # doesn't consider the number to be negative, and won't sign extend.
146
- -(2**63 - ((hiword & 0x7fffffff) << 32 | loword))
147
- else
148
- hiword << 32 | loword
149
- end
139
+ # 8 byte integers are always signed
140
+ when 3 then buff.unpack("q>")[0]
141
+ # 16 byte integers are used to represent unsigned 8 byte integers
142
+ # where the unsigned value is stored in the lower 8 bytes and the
143
+ # upper 8 bytes are unused.
144
+ when 4 then buff.unpack("Q>Q>")[1]
150
145
  end
151
146
  )
152
147
  end
@@ -474,25 +469,19 @@ module CFPropertyList
474
469
 
475
470
  # Codes an integer to binary format
476
471
  def int_to_binary(value)
472
+ # Note: nbytes is actually an exponent. number of bytes = 2**nbytes.
477
473
  nbytes = 0
478
- nbytes = 1 if value > 0xFF # 1 byte integer
479
- nbytes += 1 if value > 0xFFFF # 4 byte integer
480
- nbytes += 1 if value > 0xFFFFFFFF # 8 byte integer
481
- nbytes = 3 if value < 0 # 8 byte integer, since signed
474
+ nbytes = 1 if value > 0xFF # 1 byte unsigned integer
475
+ nbytes += 1 if value > 0xFFFF # 4 byte unsigned integer
476
+ nbytes += 1 if value > 0xFFFFFFFF # 8 byte unsigned integer
477
+ nbytes += 1 if value > 0x7FFFFFFFFFFFFFFF # 8 byte unsigned integer, stored in lower half of 16 bytes
478
+ nbytes = 3 if value < 0 # signed integers always stored in 8 bytes
482
479
 
483
480
  Binary.type_bytes(0b0001, nbytes) <<
484
- if nbytes < 3
485
- [value].pack(
486
- if nbytes == 0 then "C"
487
- elsif nbytes == 1 then "n"
488
- else "N"
489
- end
490
- )
491
- else
492
- # 64 bit signed integer; we need the higher and the lower 32 bit of the value
493
- high_word = value >> 32
494
- low_word = value & 0xFFFFFFFF
495
- [high_word,low_word].pack("NN")
481
+ if nbytes < 4
482
+ [value].pack(["C", "n", "N", "q>"][nbytes])
483
+ else # nbytes == 4
484
+ [0,value].pack("Q>Q>")
496
485
  end
497
486
  end
498
487
 
@@ -72,28 +72,12 @@ module CFPropertyList
72
72
  end
73
73
  end
74
74
 
75
- class String
76
- unless("".respond_to?(:bytesize)) then
77
- def bytesize
78
- self.length
79
- end
80
- end
81
- end
82
-
83
75
  dirname = File.dirname(__FILE__)
84
76
  require dirname + '/rbCFPlistError.rb'
85
77
  require dirname + '/rbCFTypes.rb'
86
78
  require dirname + '/rbBinaryCFPropertyList.rb'
87
79
  require dirname + '/rbPlainCFPropertyList.rb'
88
80
 
89
- require 'iconv' unless "".respond_to?("encode")
90
-
91
- # ensure that the module and class exist
92
- module Enumerable
93
- class Enumerator
94
- end
95
- end
96
-
97
81
  begin
98
82
  require dirname + '/rbLibXMLParser.rb'
99
83
  temp = LibXML::XML::Parser::Options::NOBLANKS # check if we have a version with parser options
@@ -144,7 +128,7 @@ module CFPropertyList
144
128
  when Time, DateTime, Date
145
129
  CFDate.new(object)
146
130
 
147
- when Array, Enumerator, Enumerable::Enumerator
131
+ when Array, Enumerator
148
132
  ary = Array.new
149
133
  object.each do |o|
150
134
  ary.push CFPropertyList.guess(o, options)
@@ -213,7 +197,7 @@ module CFPropertyList
213
197
 
214
198
  module_function :guess, :native_types
215
199
 
216
- # Class representing a CFPropertyList. Instanciate with #new
200
+ # Class representing a CFPropertyList. Instantiate with #new
217
201
  class List
218
202
  # Format constant for binary format
219
203
  FORMAT_BINARY = 1
@@ -5,6 +5,7 @@ require 'libxml'
5
5
  module CFPropertyList
6
6
  # XML parser
7
7
  class LibXMLParser < XMLParserInterface
8
+ PARSER_OPTIONS = LibXML::XML::Parser::Options::NOBLANKS|LibXML::XML::Parser::Options::NONET
8
9
  # read a XML file
9
10
  # opts::
10
11
  # * :file - The filename of the file to load
@@ -13,9 +14,9 @@ module CFPropertyList
13
14
  doc = nil
14
15
 
15
16
  if(opts.has_key?(:file)) then
16
- doc = LibXML::XML::Document.file(opts[:file],:options => LibXML::XML::Parser::Options::NOBLANKS|LibXML::XML::Parser::Options::NOENT)
17
+ doc = LibXML::XML::Document.file(opts[:file],:options => PARSER_OPTIONS)
17
18
  else
18
- doc = LibXML::XML::Document.string(opts[:data],:options => LibXML::XML::Parser::Options::NOBLANKS|LibXML::XML::Parser::Options::NOENT)
19
+ doc = LibXML::XML::Document.string(opts[:data],:options => PARSER_OPTIONS)
19
20
  end
20
21
 
21
22
  if doc
@@ -5,6 +5,7 @@ require 'nokogiri'
5
5
  module CFPropertyList
6
6
  # XML parser
7
7
  class NokogiriXMLParser < ParserInterface
8
+ PARSER_OPTIONS = Nokogiri::XML::ParseOptions::NOBLANKS|Nokogiri::XML::ParseOptions::NONET
8
9
  # read a XML file
9
10
  # opts::
10
11
  # * :file - The filename of the file to load
@@ -12,9 +13,9 @@ module CFPropertyList
12
13
  def load(opts)
13
14
  doc = nil
14
15
  if(opts.has_key?(:file)) then
15
- File.open(opts[:file], "rb") { |fd| doc = Nokogiri::XML::Document.parse(fd, nil, nil, Nokogiri::XML::ParseOptions::NOBLANKS|Nokogiri::XML::ParseOptions::NOENT) }
16
+ File.open(opts[:file], "rb") { |fd| doc = Nokogiri::XML::Document.parse(fd, nil, nil, PARSER_OPTIONS) }
16
17
  else
17
- doc = Nokogiri::XML::Document.parse(opts[:data], nil, nil, Nokogiri::XML::ParseOptions::NOBLANKS|Nokogiri::XML::ParseOptions::NOENT)
18
+ doc = Nokogiri::XML::Document.parse(opts[:data], nil, nil, PARSER_OPTIONS)
18
19
  end
19
20
 
20
21
  if doc
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: CFPropertyList
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.5
4
+ version: 3.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian Kruse
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-27 00:00:00.000000000 Z
11
+ date: 2020-12-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -30,10 +30,11 @@ email: cjk@defunct.ch
30
30
  executables: []
31
31
  extensions: []
32
32
  extra_rdoc_files:
33
- - README
33
+ - README.rdoc
34
34
  files:
35
35
  - LICENSE
36
- - README
36
+ - README.md
37
+ - README.rdoc
37
38
  - THANKS
38
39
  - lib/cfpropertylist.rb
39
40
  - lib/cfpropertylist/rbBinaryCFPropertyList.rb
@@ -44,11 +45,11 @@ files:
44
45
  - lib/cfpropertylist/rbNokogiriParser.rb
45
46
  - lib/cfpropertylist/rbPlainCFPropertyList.rb
46
47
  - lib/cfpropertylist/rbREXMLParser.rb
47
- homepage: http://github.com/ckruse/CFPropertyList
48
+ homepage: https://github.com/ckruse/CFPropertyList
48
49
  licenses:
49
50
  - MIT
50
51
  metadata: {}
51
- post_install_message:
52
+ post_install_message:
52
53
  rdoc_options: []
53
54
  require_paths:
54
55
  - lib
@@ -63,9 +64,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
63
64
  - !ruby/object:Gem::Version
64
65
  version: '0'
65
66
  requirements: []
66
- rubyforge_project:
67
- rubygems_version: 2.5.1
68
- signing_key:
67
+ rubygems_version: 3.0.3
68
+ signing_key:
69
69
  specification_version: 4
70
70
  summary: Read, write and manipulate both binary and XML property lists as defined
71
71
  by apple