# Read a gzip file with gzip\_lines codec

**URL:** https://discuss.elastic.co/t/read-a-gzip-file-with-gzip-lines-codec/24558
**Category:** Logstash
**Created:** [June 29, 2015, 3:44pm UTC](https://discuss.elastic.co/t/read-a-gzip-file-with-gzip-lines-codec/24558 "2015-06-29T15:44:50Z")
**Posts on this page:** 1
**Showing post:** 12

<div class="post-metadata">

### Author: ![TC\_Huang](https://avatars.discourse-cdn.com/v4/letter/t/7993a0/32.png) [@TC\_Huang](https://discuss.elastic.co/u/TC_Huang)
#### Post date: [January 12, 2016, 9:42am UTC](https://discuss.elastic.co/t/read-a-gzip-file-with-gzip-lines-codec/24558/12 "2016-01-12T09:42:34Z")

</div>

**Clone Source**  
`git clone https://github.com/logstash-plugins/logstash-codec-gzip_lines`

**Change gzip\_lines.rb**  
`logstash-codec-gzip_lines/lib/logstash/codecs/gzip_lines.rb`  
line 32 `@decoder = Zlib::GzipReader.open(data)`

> <https://github.com/logstash-plugins/logstash-codec-gzip_lines/blob/master/lib/logstash/codecs/gzip_lines.rb>

**Build Gem File**  
`cd logstash-codec-gzip_lines`  
`gem build logstash-code-gzip_lines.gemspec`

**Reinstall logstash-codec-gzip\_lines**  
`cd logstash`  
`bin/plugin install /opt/logstash-codec-gzip_lines/logstash-codec-gzip_lines-2.0.2.gem`

**Create list.txt File**  
Write by yourself gzip\_lines.rb and run it. It will create list.txt file.

Sample code:  
class GzipLines  
attr\_accessor :list\_path

```
  public
  def create_list(data_path)
    #unless File.exist?(self.list_path)
    open(self.list_path,"w")
    #end

    folders = entries_list(data_path)

    folders.each do |folder|
      files = file_list(data_path+folder)
      files.each do |file|
        open(self.list_path, "a") { |f| f << data_path+folder+'/'+file.to_s+"\n" }
      end
    end
  end

  def entries_list(basedir)
    Dir.entries(basedir).select {|entry| File.directory? File.join(basedir, entry) and !(entry =='.' || entry =='..')}
  end

  def file_list(folder_path)
    Dir.chdir(folder_path)
    files = Dir.glob('*.gz')
  end
end

    gzip_lines = GzipLines.new
    gzip_lines.list_path = '/opt/logstash/list.txt'
    gzip_lines.create_list('/home/tsanchin/rawdata/')

```

**Config logstash.conf to read list.txt file**  
file {  
type =\> "gzip"  
path =\> "/opt/logstash/list.txt"  
start\_position =\> "beginning"  
sincedb\_path =\> "gzip"  
codec =\> gzip\_lines  
}

---

_[View the full topic](https://discuss.elastic.co/t/read-a-gzip-file-with-gzip-lines-codec/24558)._
