]> git.ipfire.org Git - thirdparty/xz.git/commitdiff
liblzma: Add generic support for input seeking (LZMA_SEEK).
authorLasse Collin <lasse.collin@tukaani.org>
Thu, 30 Mar 2017 17:00:09 +0000 (20:00 +0300)
committerLasse Collin <lasse.collin@tukaani.org>
Thu, 30 Mar 2017 17:00:09 +0000 (20:00 +0300)
Also mention LZMA_SEEK in xz/message.c to silence a warning.

src/liblzma/api/lzma/base.h
src/liblzma/common/common.c
src/xz/message.c

index a6005accc93d813042af29a5561f95153f4b1854..9b3e9e1a152d936f46e8c97de863f7bbbaa22755 100644 (file)
@@ -234,6 +234,23 @@ typedef enum {
                 * can be a sign of a bug in liblzma. See the documentation
                 * how to report bugs.
                 */
+
+       LZMA_SEEK               = 12
+               /**<
+                * \brief       Request to change the input file position
+                *
+                * Some coders can do random access in the input file. The
+                * initialization functions of these coders take the file size
+                * as an argument. No other coders can return LZMA_SEEK.
+                *
+                * When this value is returned, the application must seek to
+                * the file position given in lzma_stream.seek_in. This value
+                * is guaranteed to never exceed the file size that was
+                * specified at the coder initialization.
+                *
+                * After seeking the application should read new input and
+                * pass it normally via lzma_stream.next_in and .avail_in.
+                */
 } lzma_ret;
 
 
@@ -514,7 +531,19 @@ typedef struct {
        void *reserved_ptr2;
        void *reserved_ptr3;
        void *reserved_ptr4;
-       uint64_t reserved_int1;
+
+       /**
+        * \brief       New seek input position for LZMA_SEEK
+        *
+        * When lzma_code() returns LZMA_SEEK, the new input position needed
+        * by liblzma will be available seek_in. The value is guaranteed to
+        * not exceed the file size that was specified when this lzma_stream
+        * was initialized.
+        *
+        * In all other situations the value of this variable is undefined.
+        */
+       uint64_t seek_in;
+
        uint64_t reserved_int2;
        size_t reserved_int3;
        size_t reserved_int4;
index 57e3f8ebd62a64a3325b2b9ace1ab7c9470cc89c..8ffe976423b9a532f03b358f9b1a63dc543ec1ff 100644 (file)
@@ -207,7 +207,6 @@ lzma_code(lzma_stream *strm, lzma_action action)
                        || strm->reserved_ptr2 != NULL
                        || strm->reserved_ptr3 != NULL
                        || strm->reserved_ptr4 != NULL
-                       || strm->reserved_int1 != 0
                        || strm->reserved_int2 != 0
                        || strm->reserved_int3 != 0
                        || strm->reserved_int4 != 0
@@ -318,6 +317,17 @@ lzma_code(lzma_stream *strm, lzma_action action)
                ret = LZMA_OK;
                break;
 
+       case LZMA_SEEK:
+               strm->internal->allow_buf_error = false;
+
+               // If LZMA_FINISH was used, reset it back to the
+               // LZMA_RUN-based state so that new input can be supplied
+               // by the application.
+               if (strm->internal->sequence == ISEQ_FINISH)
+                       strm->internal->sequence = ISEQ_RUN;
+
+               break;
+
        case LZMA_STREAM_END:
                if (strm->internal->sequence == ISEQ_SYNC_FLUSH
                                || strm->internal->sequence == ISEQ_FULL_FLUSH
index f88c1231e7d5d84a9228777811ed762c99ef525f..41de60c734b3fff8c883a68760f4cbb693575390 100644 (file)
@@ -818,6 +818,7 @@ message_strm(lzma_ret code)
        case LZMA_STREAM_END:
        case LZMA_GET_CHECK:
        case LZMA_PROG_ERROR:
+       case LZMA_SEEK:
                // Without "default", compiler will warn if new constants
                // are added to lzma_ret, it is not too easy to forget to
                // add the new constants to this function.