473,394 Members | 1,740 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Is it possible to embed a zipped text file, then unzip or read from it at runtime?

pardon my ignorance as I am a self-taught hobbyist programmer.

I am curious after reading up on SharpZipLib. Can I embed a zipped txt file
in my program? Then either read from within the zip file or unzip and read
it? I currently have an embedded text file that contains a list that is
read into an array. I'm always looking to save space. And I could reduce my
file size 75% if it was zipped! I have looked at the SharpZipLib web site,
downloaded their examples. I don't see any that demonstrate this. They
mainly seem to demonstrate zipping/unzipping files/folders on the local
drives.

Thanks in advance :)
Nov 16 '05 #1
10 4488
Hi,

You can embed your zipped file as binary data in a resource file. Extract
this data into a Stream and
pass it to the SharpZipLib as if it was a file stream. This should work
fine.

-c

http://www.typemismatch.com/

"Yogi_Bear_79" <IT*****@spamfree.com> wrote in message
news:Eq********************@comcast.com...
pardon my ignorance as I am a self-taught hobbyist programmer.

I am curious after reading up on SharpZipLib. Can I embed a zipped txt
file
in my program? Then either read from within the zip file or unzip and read
it? I currently have an embedded text file that contains a list that is
read into an array. I'm always looking to save space. And I could reduce
my
file size 75% if it was zipped! I have looked at the SharpZipLib web site,
downloaded their examples. I don't see any that demonstrate this. They
mainly seem to demonstrate zipping/unzipping files/folders on the local
drives.

Thanks in advance :)

Nov 16 '05 #2
Any chance you coud give an example of how to do this? Currently the file
is a .txt Are yousaying convert it to binary, then zip it. THen use
SharpZipLib to unzip it at run time to read it's contents? All the while
keeping everything embedded so my .exe is stand alone?
"typeMisMatch" <ne**@ip80.com> wrote in message
news:u9*************@TK2MSFTNGP09.phx.gbl...
Hi,

You can embed your zipped file as binary data in a resource file. Extract
this data into a Stream and
pass it to the SharpZipLib as if it was a file stream. This should work
fine.

-c

http://www.typemismatch.com/

"Yogi_Bear_79" <IT*****@spamfree.com> wrote in message
news:Eq********************@comcast.com...
pardon my ignorance as I am a self-taught hobbyist programmer.

I am curious after reading up on SharpZipLib. Can I embed a zipped txt
file
in my program? Then either read from within the zip file or unzip and read it? I currently have an embedded text file that contains a list that is
read into an array. I'm always looking to save space. And I could reduce my
file size 75% if it was zipped! I have looked at the SharpZipLib web site, downloaded their examples. I don't see any that demonstrate this. They
mainly seem to demonstrate zipping/unzipping files/folders on the local
drives.

Thanks in advance :)


Nov 16 '05 #3

I think you could also add your zip into your solution
and in the properties for it specify an embedded resource

You could then read the file using ResourceManager
class

google for C# ResourceManager embedded and I am sure you
will get some examples

-----Original Message-----
Any chance you coud give an example of how to do this? Currently the fileis a .txt Are yousaying convert it to binary, then zip it. THen useSharpZipLib to unzip it at run time to read it's contents? All the whilekeeping everything embedded so my .exe is stand alone?
"typeMisMatch" <ne**@ip80.com> wrote in message
news:u9*************@TK2MSFTNGP09.phx.gbl...
Hi,

You can embed your zipped file as binary data in a resource file. Extract
this data into a Stream and
pass it to the SharpZipLib as if it was a file stream. This should work fine.

-c

http://www.typemismatch.com/

"Yogi_Bear_79" <IT*****@spamfree.com> wrote in message
news:Eq********************@comcast.com...
> pardon my ignorance as I am a self-taught hobbyist programmer. >
>
>
> I am curious after reading up on SharpZipLib. Can I embed a zipped txt > file
> in my program? Then either read from within the zip file or unzip and
read > it? I currently have an embedded text file that
contains a list that is > read into an array. I'm always looking to save space. And I could
reduce > my
> file size 75% if it was zipped! I have looked at the
SharpZipLib web
site, > downloaded their examples. I don't see any that

demonstrate this. They > mainly seem to demonstrate zipping/unzipping files/folders on the local > drives.
>
>
>
> Thanks in advance :)
>
>


.

Nov 16 '05 #4
Yogi_Bear_79 <IT*****@spamfree.com> wrote:
Any chance you coud give an example of how to do this? Currently the file
is a .txt Are yousaying convert it to binary, then zip it.
No, just zip it. In fact, gzip it instead - there's no need to have a
zip file containing a single embedded file when you can just have the
gzip file and not worry about ZipEntry instances etc.
THen use SharpZipLib to unzip it at run time to read it's contents?
Yes.
All the while keeping everything embedded so my .exe is stand alone?


Yes.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #5
Jon,

Ok I guess I need some hints. All I have gotten accomplished so far is using
gzip to zip the file. I now have an emedded file. Previously I had an
embedded .txt file that I read into an ArrayList...Code snippet below. I've
reviewed the samples and searched the net and I'm not sure where to go from
here. Does the file get unzipped to a temp hard drive location then read
with the below code, or is unzipped and read into the ArrayList all from
memory?

private void AddRestrictedSites()
{
using (Stream
stream=GetType().Assembly.GetManifestResourceStrea m("Build_Script.Sites.txt"
))
{
using (StreamReader reader = new StreamReader(stream))
{
string line;
while ( (line=reader.ReadLine()) != null)
{
resourceSites.Add(line);
}
}
}

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Yogi_Bear_79 <IT*****@spamfree.com> wrote:
Any chance you coud give an example of how to do this? Currently the file is a .txt Are yousaying convert it to binary, then zip it.


No, just zip it. In fact, gzip it instead - there's no need to have a
zip file containing a single embedded file when you can just have the
gzip file and not worry about ZipEntry instances etc.
THen use SharpZipLib to unzip it at run time to read it's contents?


Yes.
All the while keeping everything embedded so my .exe is stand alone?


Yes.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #6
Yogi_Bear_79 <IT*****@spamfree.com> wrote:
Ok I guess I need some hints. All I have gotten accomplished so far is using
gzip to zip the file. I now have an emedded file. Previously I had an
embedded .txt file that I read into an ArrayList...Code snippet below. I've
reviewed the samples and searched the net and I'm not sure where to go from
here. Does the file get unzipped to a temp hard drive location then read
with the below code, or is unzipped and read into the ArrayList all from
memory?


It's all done in memory. All you need is a single extra using block
between fetching the stream and passing it to a reader:

private void AddRestrictedSites()
{
using (Stream stream=GetType().Assembly.GetManifestResourceStrea m
("Build_Script.Sites.txt"))
{
using (Stream decompressedStream = new GzipInputStream(stream)
{
using (StreamReader reader = new StreamReader
(decompressedStream))
{
string line;
while ( (line=reader.ReadLine()) != null)
{
resourceSites.Add(line);
}
}
}
}
}

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #7
I added the code to my test program. Below I added the using directives that
I have in this class as well. I checked these against the samples for
SharpZipLib and they appear correct to me. Yet I get the following error:
(31): Cannot implicitly convert type '<error>' to 'System.IDisposable'
(31): The type or namespace name 'GzipInputStream' could not be found (are
you missing a using directive or an assembly reference?)
It is erroring on the following line of code:
using (Stream decompressedStream = new GzipInputStream(stream)
Specifically it doesn't seem to knwo what to do with
GzipInputStream

It's all done in memory. All you need is a single extra using block
between fetching the stream and passing it to a reader:


using System;
using System.Collections;
using System.IO;
using System.Reflection;
using Microsoft.Win32;
using ICSharpCode.SharpZipLib.GZip;

private void AddRestrictedSites()
{
using (Stream
stream=GetType().Assembly.GetManifestResourceStrea m("Build_Script.Sites.txt"
))
{
using (Stream decompressedStream = new GzipInputStream(stream))
{
using (StreamReader reader = new StreamReader(stream))
{
string line;
while ( (line=reader.ReadLine()) != null)
{
resourceSites.Add(line);
}
}
}
foreach(string x in resourceSites)
{
Console.WriteLine(x);
}
}//end
Nov 16 '05 #8
I added the code to my test program. Below I added the using directives that
I have in this class as well. I checked these against the samples for
SharpZipLib and they appear correct to me. Yet I get the following error:
(31): Cannot implicitly convert type '<error>' to 'System.IDisposable'
(31): The type or namespace name 'GzipInputStream' could not be found (are
you missing a using directive or an assembly reference?)
It is erroring on the following line of code:
using (Stream decompressedStream = new GzipInputStream(stream)
Specifically it doesn't seem to knwo what to do with
GzipInputStream

It's all done in memory. All you need is a single extra using block
between fetching the stream and passing it to a reader:


using System;
using System.Collections;
using System.IO;
using System.Reflection;
using Microsoft.Win32;
using ICSharpCode.SharpZipLib.GZip;

private void AddRestrictedSites()
{
using (Stream
stream=GetType().Assembly.GetManifestResourceStrea m("Build_Script.Sites.txt"
))
{
using (Stream decompressedStream = new GzipInputStream(stream))
{
using (StreamReader reader = new StreamReader(stream))
{
string line;
while ( (line=reader.ReadLine()) != null)
{
resourceSites.Add(line);
}
}
}
foreach(string x in resourceSites)
{
Console.WriteLine(x);
}
}//end
Nov 16 '05 #9
Getting further now. I got the program to compile without errors. I had a
letter lowercase instead of uppercase.
But now I get this error when I test run.

An unhandled exception of type 'System.ArgumentNullException' occurred in
icsharpcode.sharpziplib.dll
Additional information: Value cannot be null.

It is idicating the following line of code as the probelm point:
using (Stream decompressedStream = new GZipInputStream(stream))

From what I can tell, it seems that the program is not recognizing the .gz
file. The file is an embedded .gz file.
I ziped it with GZIP via the command line with the following syntax C:\gzip
sites

private void AddRestrictedSites()
{
using (Stream stream =
GetType().Assembly.GetManifestResourceStream("site s.gz"))
{
using (Stream decompressedStream = new GZipInputStream(stream))
{
using (StreamReader reader = new StreamReader(decompressedStream))
{
string line;
while ( (line=reader.ReadLine()) != null)
{
resourceSites.Add(line);
}
}
}
}

foreach(string x in resourceSites)
{
Debug.WriteLine(x);
}
}
Nov 16 '05 #10
Disregard, and thanks for the support!
After stareing at it long enough I realized I pulled out the fully qualified
name for my file, thus the program couldn't find it!
"Yogi_Bear_79" <IT*****@spamfree.com> wrote in message
news:6p********************@comcast.com...
Getting further now. I got the program to compile without errors. I had a
letter lowercase instead of uppercase.
But now I get this error when I test run.

An unhandled exception of type 'System.ArgumentNullException' occurred in
icsharpcode.sharpziplib.dll
Additional information: Value cannot be null.

It is idicating the following line of code as the probelm point:
using (Stream decompressedStream = new GZipInputStream(stream))

From what I can tell, it seems that the program is not recognizing the .gz
file. The file is an embedded .gz file.
I ziped it with GZIP via the command line with the following syntax C:\gzip sites

private void AddRestrictedSites()
{
using (Stream stream =
GetType().Assembly.GetManifestResourceStream("site s.gz"))
{
using (Stream decompressedStream = new GZipInputStream(stream))
{
using (StreamReader reader = new StreamReader(decompressedStream))
{
string line;
while ( (line=reader.ReadLine()) != null)
{
resourceSites.Add(line);
}
}
}
}

foreach(string x in resourceSites)
{
Debug.WriteLine(x);
}
}

Nov 16 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Craig D | last post by:
I got really tired of unpacking a distutils package, installing then cleaning up. So I wrote distinstall.py - it reads a zip file, unpacks it, installs the bits and cleans up. I've only used it on...
7
by: Chris | last post by:
Hi Where can I find info on unzipping file with VB.NET. I need to unzip a winzip file with my application Thanks
2
by: Peter yeshew | last post by:
Create a database in a zipped format I have a function that creates a database. Is there any way to make the function create the database in a zipped form?TThe function i have is: ...
1
by: johnnyh | last post by:
I am currently using ASP.Net / C# to partially upload the first 100K of a CSV file to programattically extract the header information for field mapping against our database and for a test sample of...
2
by: Chris Thunell | last post by:
I have a sql database that stores documents (word and excel files) inside a field. These documents can be 10mb or larger in size. When running on my local network the files load very quickly, but...
9
by: peter.bremer | last post by:
Hi all, I've got a SQL Server database that contains zipped information stored in (binary) image fields. To complicate things, this zipped data is combined with plain-text data. I've verified...
0
by: flaviosemeao | last post by:
Hi guys, I am gonna ask the same question again regarding tweening in text fields. I already read some Adobe documentation and I understood that text field has its property _alpha available just...
0
by: VigneshS | last post by:
Hi, I am a newbie to Globalization and Localisation Concepts. I tried almost all the methods of the Globalization concepts. But i cannot be able to embed a text file within a Resource. ...
3
by: s3raph | last post by:
Hi all, I have just inherited some code that sends a file from server to client. However, the code only works for text files, and I'm trying to modify it so that it can send and receive zipped...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.