How to compress ZIP files in SketchUp plugin development?

I am developing a SketchUp plugin and there’s a feature where I need to compress the files I generate into a zip file. However, it seems that the built-in Ruby does not support this function. I’ve tried using Zlib, but it doesn’t preserve the file structure. Yes, I need to have at least one file in this zip file, and after decompression, the file can retain its original filename. How should I go about doing this?

(MIsunderstood request - Re: Packaging extension as an RBZ)

An extension needs both a registrar file (to register it’s SketchupExtension data object) and a subfolder of the same name that contains the extension’s working and support files & folders.

See the Technical Requirements section on this page:
Extension Development Best Practices | SketchUp Help

To ZIP the registrar file and the extension subfolder is simple on Windows platform (it’s built-in.)
In Windows File Explorer, select the registrar file and folder, then right-click the selection and choose:
Send to > Compressed (zipped) folder

Windows will create the archive with the same name as the extension folder but with a .zip filetype.
The filename will be highlighted for edit and you can edit the suggested name at this time.
I usually immediately click the right arrow key to put the caret just before the dot, and then add a “_” and a version number, lastly changing the .zip to .rbz so SketchUp can install it.

Thank you for your answer, perhaps my explanation wasn’t clear enough. I’ve developed a plugin, and one of its features is to save the data I’ve computed as a TEST.XML file (either an actual file or a file in memory), then compress this XML file into a ZIP file using a command or method. But I need to retain the original name of this XML file. In other words, when I decompress this file using other software (like 7ZIP, ZIP, etc.), I can retrieve a file that still retains the name TEST.XML.

You would need to use something like RubyZip

Since you can’t really depend on gems in SketchUp you will need to take the code from the library and wrap it in your own namespace.


Okay, I collapsed what I wrote. Your topic title said “plugin development”.
What you really want (and you can edit the topic title) is plugin runtime zipping of files.

I second what Neil said above.

Thank you so much for your help! Using RubyZip and wrapping it in my own namespace worked perfectly for my SketchUp plugin. I really appreciate your suggestion, and it saved me a lot of time. Thanks again!