public inbox for cygwin-apps@cygwin.com
 help / color / mirror / Atom feed
From: Jon Turney <jon.turney@dronecode.org.uk>
To: cygwin-apps@cygwin.com
Cc: Jon Turney <jon.turney@dronecode.org.uk>
Subject: [PATCH setup 1/2] Add underlying() method to io_stream class
Date: Sun, 23 Apr 2023 15:43:29 +0100	[thread overview]
Message-ID: <20230423144330.3107-2-jon.turney@dronecode.org.uk> (raw)
In-Reply-To: <20230423144330.3107-1-jon.turney@dronecode.org.uk>

Add underlying() method to io_stream class.  This saves having to pass
around both original and decompressed stream, just so you can call
tell() on the original stream.

For a non-compressed stream, it simply returns that io_stream object.

In the case of a compressed stream, this returns the io_stream object
for the underlying file stream.

Move the original and owns_original members up to compress class from
it's subclasses to facilitate that.

Also clean up some cruft in io_stream.h
---
 compress.h       | 13 +++++++++++++
 compress_bz.cc   |  2 --
 compress_bz.h    |  2 --
 compress_gz.h    |  2 --
 compress_xz.cc   |  2 --
 compress_xz.h    |  2 --
 compress_zstd.cc |  2 --
 compress_zstd.h  |  2 --
 io_stream.h      | 31 ++++++-------------------------
 9 files changed, 19 insertions(+), 39 deletions(-)

diff --git a/compress.h b/compress.h
index 1692fa6..5e84408 100644
--- a/compress.h
+++ b/compress.h
@@ -21,6 +21,11 @@
 class compress:public io_stream
 {
 public:
+  compress () :
+    original(NULL),
+    owns_original(true)
+  { };
+
   /* Get a decompressed stream from a normal stream. If this function returns non-null
    * a valid compress header was found. The io_stream pointer passed to decompress
    * should be discarded. The old io_stream will be automatically closed when the 
@@ -48,6 +53,14 @@ public:
   virtual const char *next_file_name () = 0;
   /* if you are still needing these hints... give up now! */
   virtual ~compress () = 0;
+
+  virtual io_stream *underlying ()
+  {
+    return original;
+  }
+protected:
+  io_stream *original;
+  bool owns_original;
 };
 
 #endif /* SETUP_COMPRESS_H */
diff --git a/compress_bz.cc b/compress_bz.cc
index d801de1..f8a1199 100644
--- a/compress_bz.cc
+++ b/compress_bz.cc
@@ -26,7 +26,6 @@
 compress_bz::compress_bz (io_stream * parent) : peeklen (0), position (0)
 {
   /* read only via this constructor */
-  original = 0;
   lasterr = 0;
   if (!parent || parent->error ())
     {
@@ -34,7 +33,6 @@ compress_bz::compress_bz (io_stream * parent) : peeklen (0), position (0)
       return;
     }
   original = parent;
-  owns_original = true;
   init_state();
 }
 
diff --git a/compress_bz.h b/compress_bz.h
index 9ab59d7..6ccccfc 100644
--- a/compress_bz.h
+++ b/compress_bz.h
@@ -56,8 +56,6 @@ public:
   /* if you are still needing these hints... give up now! */
     virtual ~ compress_bz ();
 private:
-  io_stream *original;
-  bool owns_original;
   char peekbuf[512];
   size_t peeklen;
   int lasterr;
diff --git a/compress_gz.h b/compress_gz.h
index c7ae14b..05b4b7b 100644
--- a/compress_gz.h
+++ b/compress_gz.h
@@ -67,8 +67,6 @@ private:
   void putLong (unsigned long);
   void destroy ();
   int do_flush (int);
-  io_stream *original;
-  bool owns_original;
   const char *openmode;
   /* from zlib */
   z_stream stream;
diff --git a/compress_xz.cc b/compress_xz.cc
index b91c8a4..5c34a54 100644
--- a/compress_xz.cc
+++ b/compress_xz.cc
@@ -45,8 +45,6 @@ le64dec(const void *pp)
  */
 compress_xz::compress_xz (io_stream * parent)
 :
-  original(NULL),
-  owns_original(true),
   peeklen(0),
   lasterr(0),
   compression_type (COMPRESSION_UNKNOWN)
diff --git a/compress_xz.h b/compress_xz.h
index 9be7822..48e620d 100644
--- a/compress_xz.h
+++ b/compress_xz.h
@@ -44,8 +44,6 @@ public:
 private:
   compress_xz () {};
 
-  io_stream *original;
-  bool owns_original;
   char peekbuf[512];
   size_t peeklen;
   int lasterr;
diff --git a/compress_zstd.cc b/compress_zstd.cc
index 8d6e51f..ba0e491 100644
--- a/compress_zstd.cc
+++ b/compress_zstd.cc
@@ -24,8 +24,6 @@
  */
 compress_zstd::compress_zstd (io_stream * parent)
 :
-  original(NULL),
-  owns_original(true),
   lasterr(0)
 {
   /* read only */
diff --git a/compress_zstd.h b/compress_zstd.h
index b9b541e..c30d1a8 100644
--- a/compress_zstd.h
+++ b/compress_zstd.h
@@ -39,8 +39,6 @@ public:
 private:
   compress_zstd () {};
 
-  io_stream *original;
-  bool owns_original;
   int lasterr;
   void create ();
   void destroy ();
diff --git a/io_stream.h b/io_stream.h
index f19e134..68915b1 100644
--- a/io_stream.h
+++ b/io_stream.h
@@ -47,15 +47,6 @@ typedef enum
 }
 path_type_t;
 
-typedef enum
-{
-  IO_STREAM_INVALID,
-  IO_STREAM_STREAM,
-  IO_STREAM_COMPRESS,
-  IO_STREAM_ARCHIVE
-}
-io_stream_type_t;
-
 typedef enum
 {
   IO_STREAM_SYMLINK,
@@ -143,27 +134,17 @@ public:
   virtual int error () = 0;
   /* hmm, yet another for the guessing books */
   virtual char *gets (char *, size_t len);
-  /* what sort of stream is this?
-   * known types are:
-   * IO_STREAM_INVALID - not a valid stream.
-   * IO_STREAM_STREAM - just another stream.
-   * IO_STREAM_COMPRESS - a compressed or compressing stream.
-   * IO_STREAM_ARCHIVE - an archive of some sort, with > 0 files.
-   * this is a crutch for real runtime type evaluation.
-   */
-  /* Find out the next stream name -
-   * ie for foo.tar.gz, at offset 0, next_file_name = foo.tar
-   * for foobar that is an archive, next_file_name is the next
-   * extractable filename.
-   */
-//  virtual const char* next_file_name() = NULL;
-  /* if you are still needing these hints... give up now! */
+
   virtual ~io_stream () = 0;
 
   io_stream& operator << (io_stream&);
   virtual void operator << (std::string) {}
   virtual void operator << (const char *) {}
-  
+
+  virtual io_stream *underlying ()
+  {
+    return this;
+  }
 protected:
   void operator= (const io_stream &);
   io_stream() {};
-- 
2.39.0


  reply	other threads:[~2023-04-23 14:43 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-23 14:43 [PATCH setup 0/2] Detect filename collisions between packages Jon Turney
2023-04-23 14:43 ` Jon Turney [this message]
2023-04-23 14:43 ` [PATCH setup 2/2] " Jon Turney
2023-04-24 16:26   ` Christian Franke
2023-04-27 16:11     ` Jon Turney
2023-04-27 17:20       ` Christian Franke
2023-04-24 16:46 ` [PATCH setup 0/2] " Corinna Vinschen
2023-04-24 18:16   ` Achim Gratz
2023-04-27 16:11     ` Jon Turney
2023-04-28  5:51       ` Brian Inglis
2023-04-30 18:25         ` Jon Turney
2023-05-04  4:14           ` Brian Inglis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230423144330.3107-2-jon.turney@dronecode.org.uk \
    --to=jon.turney@dronecode.org.uk \
    --cc=cygwin-apps@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).