/* -----------------------------------------------------------------------------
	GSFramework
	Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
----------------------------------------------------------------------------- */


#ifndef	__NIOZIP__
#define	__NIOZIP__


		#include <stdio.h>
		#include "filesystem/io_handle.h"
		#include "filesystem/io_memory.h"
		#include "container/nmap.h"
		#include "nstring/nstring.h"
		#include "memory/nauto_ptr.h"


namespace GS {
	namespace IO {

//
class	ZipHandle : public Handle
{
		friend class Zip;

		AutoPtr <Handle> h;
		Pair <String, int> *p;

public:

		ZipHandle(Base *io) : Handle(io), p(0) {}
};

/*!
	@short	Zip-based I/O.
	@author	Emmanuel Julien (ejulien@nworks.fr)
*/
class	Zip : public Base
{
		void		*zfile;
		String		password;

		Map <String, int> refc_map;
		SharedPtr <Memory> memfs;		// Support IO system.

public:

		bool		SetArchive(const char *uri, const char *password = 0);

virtual	uint		GetCaps() const;

virtual	Handle		*Open(const char *, Mode = ModeRead);
virtual	void		Close(Handle *);

virtual	bool		Delete(const char *);

virtual	size_t		Tell(Handle *);
virtual	size_t		Seek(Handle *, ptrdiff_t offset, SeekRef = SeekCurrent);

virtual	size_t		Read(Handle *, void *, size_t);
virtual	size_t		Write(Handle *, const void *, size_t);

virtual	bool		MkDir(const char *) { return false; }

		Zip(const char *uri, const char *password = 0);
		~Zip();
};

	}	// IO
}	// GS


#endif	// __NIOZIP__
