# RubyZip help needed

**URL:** <https://www.ruby-forum.com/t/rubyzip-help-needed/184118>\
**Category:** Ruby\
**Created:** [February 25, 2010, 1:07pm UTC](https://www.ruby-forum.com/t/rubyzip-help-needed/184118 "2010-02-25T13:07:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![THAKUR\_PRASHANT\_SIN](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ecc23a/32.png) [@THAKUR\_PRASHANT\_SIN](https://www.ruby-forum.com/u/THAKUR_PRASHANT_SIN)\
**Post date:** [February 25, 2010, 1:07pm UTC](https://www.ruby-forum.com/t/rubyzip-help-needed/184118/1 "2010-02-25T13:07:39Z")

</div>

I am creating zip file using ruby zip there are two versions of creating  
the zip file 1st version part of class and in 2nd version running it  
alone.  
The kmz file created with 1st version doesn’t contain complete text of  
LOC\_0.kml  
Whereas the 2nd version does contain the complete file contents…  
I.e. if LOC\_0.kml has 100 lines then 1st version kmz file contains only  
95 lines while 2nd version contains complete 100 lines.  
Can you please suggest what can be the reason ?

====================Class function======================  
require ‘zip/zip’

class ZipUtils  
attr :filename  
def initialize(filename)  
@filename=filename  
end  
def createkmzfile  
kml\_name=@filename  
puts kml\_name  
kmz\_file = kml\_name.sub(".kml",".kmz")

```
File.delete(kmz_file) if File.exists?(kmz_file)

Zip::ZipFile.open(kmz_file, Zip::ZipFile::CREATE) {
  |zf|
  zf.add(kml_name, "kml/#{kml_name}")
  zf.mkdir("images")
  imglist=Dir.glob("images/*.png")
  puts imglist
  for i in 0..imglist.size-1
    zf.add(imglist[i], imglist[i])
  end
}

```

end  
end  
==========================external file===========================  
require ‘zip/zip’

class ZipUtils  
attr :filename  
def initialize(filename)  
@filename=filename  
end  
def createkmzfile

end  
end

```
kml_name="LOC_0.kml"
kmz_file = kml_name.sub(".kml",".kmz")
   puts kml_name
File.delete(kmz_file) if File.exists?(kmz_file)

Zip::ZipFile.open(kmz_file, Zip::ZipFile::CREATE) {
  |zf|
  zf.add(kml_name, "kml/#{kml_name}")
  zf.mkdir("images")
  imglist=Dir.glob("images/*.png")
  puts imglist
  for i in 0..imglist.size-1
    zf.add(imglist[i], imglist[i])
  end
}
```

---

<div class="post-metadata">

**Author:** ![THAKUR\_PRASHANT\_SIN](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ecc23a/32.png) [@THAKUR\_PRASHANT\_SIN](https://www.ruby-forum.com/u/THAKUR_PRASHANT_SIN)\
**Post date:** [February 26, 2010, 5:20pm UTC](https://www.ruby-forum.com/t/rubyzip-help-needed/184118/2 "2010-02-26T17:20:55Z")

</div>

> Whereas the 2nd version does contain the complete file contents…  
> I.e. if LOC\_0.kml has 100 lines then 1st version kmz file contains only  
> 95 lines while 2nd version contains complete 100 lines.  
> Can you please suggest what can be the reason ?

Did you try different versions of ruby? What platform?  
-r
