ptools 1.3.0-universal-mingw32 → 1.3.1-universal-mingw32

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ODRjNGZmYTAzYTU4ZjE4NDA0OWVlZWZiZDlmMDNlNjExZWM4YWY3ZQ==
4
+ YTI0ODIwZjk4NGU5MmY2M2FkYTk3OWM4MzgwYzc0NWJmNTlhOWRjMw==
5
5
  data.tar.gz: !binary |-
6
- ZjVkYjQwMTQ0YWViOTJlMDI4NTFmYTYyYTc3MGJhNTQyNGM3NTU5Ng==
6
+ NDU1MTE1YmU3ZGFkYjc2ZWY5NmQyY2VjODQ4ZWUxNjQwMmM2ODlkNg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YjcxOWU1MmNkZTBlZjg5YTIzMTU0NWZmNjM5ZjBlMmU4NGUyZTM0MTdjYzNk
10
- NWFmNmRmZTYzZTUzYmE3N2U4NjMwZmM0MWEzZjc3M2EwNjUzMmY1NWM4NDc2
11
- NjUxODhkZDczNWVhZjIzZTRjNWRmMDNiMzc0Zjc4YTUzZWJkMjY=
9
+ OWZlYWMyNDFlYTRkM2Q0ZGVmZWRmMmI2M2Q1OWNiNjdiNjRhOGI5ODc4NGM2
10
+ YTkwNTM1YWUyYTQxZTQ2YzQ1MDYwYmMzZjJjMjAzMGJlN2JiMDg0YmNkMzVl
11
+ NmViOTNjMTgzYjk1ZDg1NDU3MTUzNDgxOTllZjQ5N2IwNDcwN2M=
12
12
  data.tar.gz: !binary |-
13
- YTUyMzY2MGRjNzM4YzE5ZDhkMWQ3MWYyNjgwNDBkYjFmMzA4NjQyYmJmYjg5
14
- ODdhMzFlNTZmZmQ4MzE0YzRiNGIwNGE5MjI2Y2MzZjdjNGYwYjkzNWI1NjMy
15
- OTJiMmNjMjE2ZTY3M2M4MDhhMzQ5ZjhmMGUwM2M3ZmJjMDIxOGY=
13
+ NWE4OTllMDVlYTUyOTM4NzAzN2Y0NjRhYzFiMzUxNzMzYzQ3MDE1NzA0YzQz
14
+ NzAxZTQ1OTJkOTAzZWE2ZTMzMDgxNDlmZmM0ZTc2ZjQxMjZjMDU1Y2E0NGU4
15
+ Yzg0OWJlZmJmNTk5MmU5MDcxOTM5Y2FjNGI0ODAyMjQ2ZjdhMDc=
data/CHANGES CHANGED
@@ -1,3 +1,7 @@
1
+ == 1.3.1 - 9-Dec-2014
2
+ * Fixed some potential issues with File.tail. Thanks go to Matt Hoyle for
3
+ the patch.
4
+
1
5
  == 1.3.0 - 8-Dec-2014
2
6
  * Made the File.tail method efficient. It's no longer slurpy, and it also no
3
7
  longer includes line endings in the result.
data/lib/ptools.rb CHANGED
@@ -3,7 +3,7 @@ require 'win32/file' if File::ALT_SEPARATOR
3
3
 
4
4
  class File
5
5
  # The version of the ptools library.
6
- PTOOLS_VERSION = '1.3.0'
6
+ PTOOLS_VERSION = '1.3.1'
7
7
 
8
8
  # :stopdoc:
9
9
 
@@ -252,30 +252,31 @@ class File
252
252
 
253
253
  # MS Windows gets unhappy if you try to seek backwards past the
254
254
  # end of the file, so we have some extra checks here and later.
255
- file_size = File.size(filename)
256
- tail_size = file_size if file_size <= tail_size
257
- line_sep = File::ALT_SEPARATOR ? "\r\n" : "\n"
255
+ file_size = File.size(filename)
256
+ read_bytes = file_size % tail_size
257
+ read_bytes = tail_size if read_bytes == 0
258
+ line_sep = File::ALT_SEPARATOR ? "\r\n" : "\n"
258
259
 
259
260
  buf = ''
260
261
 
261
262
  File.open(filename){ |fh|
262
- fh.seek(-tail_size, File::SEEK_END)
263
-
264
- while buf.count(line_sep) <= num_lines
265
- buf = fh.read(tail_size) + buf
266
- break if buf.count(line_sep) >= num_lines
267
- if tail_size * 2 < file_size
268
- fh.seek(-tail_size * 2, File::SEEK_CUR)
269
- else
270
- fh.seek(-file_size, File::SEEK_CUR)
271
- end
263
+ # Set the starting read position
264
+ position = file_size - read_bytes
265
+
266
+ # Loop until we have the lines or run out of file
267
+ while buf.scan(line_sep).size <= num_lines and position >= 0
268
+ fh.seek(position, IO::SEEK_SET)
269
+ buf = fh.read(read_bytes) + buf
270
+ read_bytes = tail_size
271
+ position -= read_bytes
272
272
  end
273
273
  }
274
274
 
275
+ lines = buf.split(line_sep).pop(num_lines)
275
276
  if block_given?
276
- buf.split(line_sep)[-num_lines..-1].each{ |line| yield line }
277
+ lines.each{ |line| yield line }
277
278
  else
278
- buf.split(line_sep)[-num_lines..-1]
279
+ lines
279
280
  end
280
281
  end
281
282
 
data/ptools.gemspec CHANGED
@@ -3,7 +3,7 @@ require 'rbconfig'
3
3
 
4
4
  Gem::Specification.new do |gem|
5
5
  gem.name = 'ptools'
6
- gem.version = '1.3.0'
6
+ gem.version = '1.3.1'
7
7
  gem.license = 'Artistic 2.0'
8
8
  gem.author = 'Daniel J. Berger'
9
9
  gem.email = 'djberg96@gmail.com'
@@ -15,7 +15,7 @@ class TC_Ptools_Constants < Test::Unit::TestCase
15
15
  end
16
16
 
17
17
  test "PTOOLS_VERSION constant is set to expected value" do
18
- assert_equal('1.3.0', File::PTOOLS_VERSION)
18
+ assert_equal('1.3.1', File::PTOOLS_VERSION)
19
19
  end
20
20
 
21
21
  test "IMAGE_EXT constant is set to array of values" do
data/test/test_tail.rb CHANGED
@@ -9,18 +9,61 @@ require 'ptools'
9
9
 
10
10
  class TC_FileTail < Test::Unit::TestCase
11
11
  def self.startup
12
+
12
13
  Dir.chdir('test') if File.exist?('test')
13
- File.open('test_file1.txt', 'w'){ |fh| 25.times{ |n| fh.puts "line#{n+1}" } }
14
+
15
+ File.open('test_file1.txt', 'w'){ |fh|
16
+ 25.times{ |n| fh.puts "line#{n+1}" }
17
+ }
18
+
19
+ # Trailing newline test
20
+ File.open('test_file_trail.txt', 'w'){ |fh|
21
+ 2.times{ |n| fh.puts "trail#{n+1}" }
22
+ fh.write "trail3"
23
+ }
24
+ File.open('test_file_trail_nl.txt', 'w'){ |fh|
25
+ 3.times{ |n| fh.puts "trail#{n+1}" }
26
+ }
27
+
28
+ # Larger files
29
+ test_tail_fmt_str = "line data data data data data data data %5s"
30
+
31
+ File.open('test_file64.txt', 'w'){ |fh|
32
+ 2000.times{ |n|
33
+ fh.puts test_tail_fmt_str % (n+1).to_s
34
+ }
35
+ }
36
+
37
+ File.open('test_file128.txt', 'w'){ |fh|
38
+ 4500.times{ |n|
39
+ fh.puts test_tail_fmt_str % (n+1).to_s
40
+ }
41
+
42
+ }
14
43
  end
15
44
 
16
45
  def setup
17
- @test_file = 'test_file1.txt'
46
+ @test_file = 'test_file1.txt'
47
+ @test_trail = 'test_file_trail.txt'
48
+ @test_trail_nl = 'test_file_trail_nl.txt'
49
+ @test_file_64 = 'test_file64.txt'
50
+ @test_file_128 = 'test_file128.txt'
18
51
 
19
- @expected_tail1 = ["line16","line17","line18","line19"]
20
- @expected_tail1.push("line20","line21","line22", "line23")
21
- @expected_tail1.push("line24","line25")
52
+ @expected_tail1 = %w{
53
+ line16 line17 line18 line19 line20
54
+ line21 line22 line23 line24 line25
55
+ }
22
56
 
23
57
  @expected_tail2 = ["line21","line22","line23","line24","line25"]
58
+
59
+ @expected_tail_more = []
60
+ 25.times{ |n| @expected_tail_more.push "line#{n+1}" }
61
+
62
+ @expected_tail_trail = %w{ trail2 trail3 }
63
+
64
+ @test_tail_fmt_str = "line data data data data data data data %5s"
65
+
66
+
24
67
  end
25
68
 
26
69
  def test_tail_basic
@@ -36,11 +79,34 @@ class TC_FileTail < Test::Unit::TestCase
36
79
  assert_equal(@expected_tail2, File.tail(@test_file, 5))
37
80
  end
38
81
 
82
+ def test_more_lines_than_file
83
+ assert_equal( @expected_tail_more, File.tail(@test_file, 30) )
84
+ end
85
+
39
86
  def test_tail_expected_errors
40
87
  assert_raises(ArgumentError){ File.tail }
41
88
  assert_raises(ArgumentError){ File.tail(@test_file, 5, 5) }
42
89
  end
43
90
 
91
+ def test_no_trailing_newline
92
+ assert_equal( @expected_tail_trail, File.tail(@test_trail, 2) )
93
+ assert_equal( @expected_tail_trail, File.tail(@test_trail_nl, 2) )
94
+ end
95
+
96
+ def test_tail_larger_than_64k
97
+ expected_tail_64k=[]
98
+ 2000.times{ |n| expected_tail_64k.push( @test_tail_fmt_str % (n+1).to_s ) }
99
+ assert_equal( expected_tail_64k, File.tail(@test_file_64, 2000) )
100
+ end
101
+
102
+ def test_tail_larger_than_128k
103
+ expected_tail_128k = []
104
+ 4500.times{ |n| expected_tail_128k.push( @test_tail_fmt_str % (n+1).to_s ) }
105
+ assert_equal( expected_tail_128k, File.tail(@test_file_128, 4500) )
106
+ end
107
+
108
+
109
+
44
110
  def teardown
45
111
  @test_file = nil
46
112
  @expected_tail1 = nil
@@ -49,5 +115,9 @@ class TC_FileTail < Test::Unit::TestCase
49
115
 
50
116
  def self.shutdown
51
117
  File.delete('test_file1.txt') if File.exist?('test_file1.txt')
118
+ File.delete('test_file64.txt') if File.exist?('test_file64.txt')
119
+ File.delete('test_file128.txt') if File.exist?('test_file128.txt')
120
+ File.delete('test_file_trail_nl.txt') if File.exist?('test_file_trail_nl.txt')
121
+ File.delete('test_file_trail.txt') if File.exist?('test_file_trail.txt')
52
122
  end
53
123
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ptools
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.3.1
5
5
  platform: universal-mingw32
6
6
  authors:
7
7
  - Daniel J. Berger
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-08 00:00:00.000000000 Z
11
+ date: 2014-12-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake