unix_utils 0.0.4 → 0.0.5

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.
@@ -1,3 +1,13 @@
1
+ == 0.0.5 / 2012-03-21
2
+
3
+ * Enhancements
4
+
5
+ * Change pipe buffer size to 64kb (it was 4mb before), which seems to make everything run faster
6
+
7
+ * Bug fixes
8
+
9
+ * Thanks to @leomao10, make sed work more reliably on large files by using its input-file argument rather than piping in data
10
+
1
11
  == 0.0.4 / 2012-03-19
2
12
 
3
13
  * Bug fixes
@@ -8,7 +8,7 @@ require "unix_utils/version"
8
8
 
9
9
  module UnixUtils
10
10
 
11
- BUFSIZE = 4_194_304
11
+ BUFSIZE = 2**16
12
12
 
13
13
  def self.curl(url, form_data = nil)
14
14
  outfile = tmp_path url
@@ -192,12 +192,13 @@ module UnixUtils
192
192
  end
193
193
  end
194
194
 
195
+ # POSIX sed, whether it's provided by sed or gsed
195
196
  def self.sed(infile, *expr)
196
197
  infile = ::File.expand_path infile
197
198
  outfile = tmp_path infile
198
- bin = available?('gsed') ? 'gsed' : 'sed'
199
- argv = [ bin, expr.map { |e| ['-e', e] } ].flatten
200
- spawn argv, :read_from => infile, :write_to => outfile
199
+ bin = available?('sed') ? 'sed' : ['gsed', '--posix']
200
+ argv = [ bin, expr.map { |e| ['-e', e] }, infile ].flatten
201
+ spawn argv, :write_to => outfile
201
202
  outfile
202
203
  end
203
204
 
@@ -1,3 +1,3 @@
1
1
  module UnixUtils
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -0,0 +1,32 @@
1
+ # encoding: UTF-8
2
+ require 'helper'
3
+ require 'tempfile'
4
+
5
+ describe "handle large file with sed" do
6
+ let(:normal_line_no) { 124000 }
7
+ let(:invalid_line_no) { 10 }
8
+ let(:input_file) { Tempfile.open('test', '/tmp') }
9
+
10
+ before do
11
+ begin
12
+ (1..normal_line_no).each do |i|
13
+ input_file.puts "\"psmith01\",\"CLASS2B\",\"Peter Smith 1\",\"YEAR2\",\"1\",\"N\",\"ADVANCED\",\"STAFF\",\"1\",\"Y\",\"Y\",\"psmith01\",\"CLASS2B\",\"Peter Smith 1\",\"YEAR2\",\"1\",\"N\",\"ADVANCED\",\"STAFF\",\"1\",\"Y\",\"Y\",\"psmith01\",\"CLASS2B\",\"Peter Smith 1\",\"YEAR2\",\"1\",\"N\",\"ADVANCED\",\"STAFF\",\"1\",\"Y\",\"Y\",\"psmith01\",\"CLASS2B\",\"Peter Smith 1\",\"YEAR2\",\"1\",\"N\",\"ADVANCED\",\"STAFF\",\"1\",\"Y\",\"Y\""
14
+ end
15
+ (1..invalid_line_no).each do |i|
16
+ input_file.puts "@!!@"
17
+ end
18
+ input_file.flush
19
+ ensure
20
+ input_file.close
21
+ end
22
+ end
23
+
24
+ it "should have 124000 lines in output file" do
25
+ output_path = UnixUtils.sed(input_file.path, ':a', "1,#{invalid_line_no}!{P;N;D;};N;ba")
26
+ UnixUtils.wc(output_path).first.must_equal normal_line_no
27
+ end
28
+
29
+ after do
30
+ input_file.unlink
31
+ end
32
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unix_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-20 00:00:00.000000000 Z
12
+ date: 2012-03-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: posix-spawn
16
- requirement: &2154399440 !ruby/object:Gem::Requirement
16
+ requirement: &2154458300 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2154399440
24
+ version_requirements: *2154458300
25
25
  description: Like FileUtils, but provides zip, unzip, bzip2, bunzip2, tar, untar,
26
26
  sed, du, md5sum, shasum, cut, head, tail, wc, unix2dos, dos2unix, iconv, curl, perl,
27
27
  etc.
@@ -39,6 +39,7 @@ files:
39
39
  - lib/unix_utils.rb
40
40
  - lib/unix_utils/version.rb
41
41
  - test/helper.rb
42
+ - test/regression/test_sed_large_file.rb
42
43
  - test/target/directory-really-a-t_a_r-shh
43
44
  - test/target/directory-really-a-z_i_p-shh
44
45
  - test/target/directory.tar
@@ -84,6 +85,7 @@ summary: Like FileUtils, but provides zip, unzip, bzip2, bunzip2, tar, untar, se
84
85
  etc.
85
86
  test_files:
86
87
  - test/helper.rb
88
+ - test/regression/test_sed_large_file.rb
87
89
  - test/target/directory-really-a-t_a_r-shh
88
90
  - test/target/directory-really-a-z_i_p-shh
89
91
  - test/target/directory.tar