zip.deflate压缩数据后，如何获取到编码后数据长度
=============================

#### 问题现象

zip.deflate压缩数据后调用zStream.totalOut，编码后zStream的totalOut都没有发生改变，一直都是0，应该怎么获取到编码后数据长度？

import { zlib } from '@kit.BasicServicesKit';

async function getTotalOutOfzStream() {
  let str \= 'hello world!';
  let arrayBufferIn \= new ArrayBuffer(str.length);
  let byteArray \= new Uint8Array(arrayBufferIn);
  for (let i \= 0, j \= str.length; i < j; i++) {
    byteArray\[i\] \= str.charCodeAt(i)
  }
  let arrayBufferOut \= new ArrayBuffer(100);
  let zStream: zlib.ZStream \= {
    nextIn: arrayBufferIn,
    availableIn: arrayBufferIn.byteLength,
    nextOut: arrayBufferOut,
    availableOut: arrayBufferOut.byteLength,
    totalOut: 0
  };
  try {
    let zip \= zlib.createZipSync();
    await zip.deflateInit(zStream, zlib.CompressLevel.COMPRESS\_LEVEL\_BEST\_SPEED)
    await zip.deflate(zStream, zlib.CompressFlushMode.FINISH)

   _ // 使用zStream获取totalOut_
    let totalOut \= zStream.totalOut
    console.info(\`The total out of zStream is \` \+ totalOut)
  } catch (e) {
    console.error(e)
  }
}

#### 解决方案

每次操作完成，需要重新getZStream()获取最新状态，参考：[压缩与解压](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/deflate-and-inflate#接口说明)。

import { zlib } from '@kit.BasicServicesKit';

async function getTotalOutOfzStream() {
  let str \= 'hello world!';
  let arrayBufferIn \= new ArrayBuffer(str.length);
  let byteArray \= new Uint8Array(arrayBufferIn);
  for (let i \= 0, j \= str.length; i < j; i++) {
    byteArray\[i\] \= str.charCodeAt(i);
  }
  let arrayBufferOut \= new ArrayBuffer(100);
  let zStream: zlib.ZStream \= {
    nextIn: arrayBufferIn,
    availableIn: arrayBufferIn.byteLength,
    nextOut: arrayBufferOut,
    availableOut: arrayBufferOut.byteLength,
    totalOut: 0
  };
  try {
    let zip \= zlib.createZipSync();
    await zip.deflateInit(zStream, zlib.CompressLevel.COMPRESS\_LEVEL\_BEST\_SPEED);
    await zip.deflate(zStream, zlib.CompressFlushMode.FINISH);

   _ // 重新getZStream()获取最新状态，然后获取totalOut_
    let totalOut \= (await zip.getZStream()).totalOut;
    console.info('The total out of zStream is ' \+ totalOut);
  } catch (e) {
    console.error(e);
  }
}

@Entry
@Component
struct Index {
  message: string \= 'Hello World';

  build() {
    RelativeContainer() {
      Text(this.message)
        .id('HelloWorld')
        .fontSize($r('app.float.page\_text\_font\_size'))
        .fontWeight(FontWeight.Bold)
        .alignRules({
          center: { anchor: '\_\_container\_\_', align: VerticalAlign.Center },
          middle: { anchor: '\_\_container\_\_', align: HorizontalAlign.Center }
        })
        .onClick(() \=\> {
          getTotalOutOfzStream();
        });
    }
    .height('100%')
    .width('100%');
  }
}