+/**
+ * Queue a block of logic data for srzip archive writes.
+ *
+ * @param[in] o Output module instance.
+ * @param[in] buf Logic data samples as byte sequence.
+ * @param[in] unitsize Logic data unit size (bytes per sample).
+ * @param[in] length Number of bytes of sample data.
+ * @param[in] flush Force ZIP archive update (queue by default).
+ *
+ * @returns SR_OK et al error codes.
+ */
+static int zip_append_queue(const struct sr_output *o,
+ uint8_t *buf, size_t unitsize, size_t length, gboolean flush)
+{
+ struct out_context *outc;
+ struct logic_buff *buff;
+ size_t send_size, remain, copy_size;
+ uint8_t *wrptr, *rdptr;
+ int ret;
+
+ outc = o->priv;
+ buff = &outc->logic_buff;
+ if (length && unitsize != buff->unit_size) {
+ sr_warn("Unexpected unit size, discarding logic data.");
+ return SR_ERR_ARG;
+ }
+
+ /*
+ * Queue most recently received samples to the local buffer.
+ * Flush to the ZIP archive when the buffer space is exhausted.
+ */
+ rdptr = buf;
+ send_size = buff->unit_size ? length / buff->unit_size : 0;
+ while (send_size) {
+ remain = buff->alloc_size - buff->fill_size;
+ if (remain) {
+ wrptr = &buff->samples[buff->fill_size * buff->unit_size];
+ copy_size = MIN(send_size, remain);
+ send_size -= copy_size;
+ buff->fill_size += copy_size;
+ memcpy(wrptr, rdptr, copy_size * buff->unit_size);
+ rdptr += copy_size * buff->unit_size;
+ remain -= copy_size;
+ }
+ if (send_size && !remain) {
+ ret = zip_append(o, buff->samples, buff->unit_size,
+ buff->fill_size * buff->unit_size);
+ if (ret != SR_OK)
+ return ret;
+ buff->fill_size = 0;
+ remain = buff->alloc_size - buff->fill_size;
+ }
+ }
+
+ /* Flush to the ZIP archive if the caller wants us to. */
+ if (flush && buff->fill_size) {
+ ret = zip_append(o, buff->samples, buff->unit_size,
+ buff->fill_size * buff->unit_size);
+ if (ret != SR_OK)
+ return ret;
+ buff->fill_size = 0;
+ }
+
+ return SR_OK;
+}
+
+/**
+ * Append analog data of a channel to an srzip archive.
+ *
+ * @param[in] o Output module instance.
+ * @param[in] values Sample data as array of floating point values.
+ * @param[in] count Number of samples (float items, not bytes).
+ * @param[in] ch_nr 1-based channel number.
+ *
+ * @returns SR_OK et al error codes.
+ */