Skip to content

ZipKit的GZip.cs 的Compress方法参数传错了 #149

@weshengyu

Description

@weshengyu

原方法把level当成size传进去了,会报错

        public static void Compress(Stream inStream, Stream outStream, bool isStreamOwner, int level)
		{
			if (inStream == null || outStream == null) {
				throw new Exception("Null Stream");
			}

			try {
				using (GZipOutputStream bzipOutput = new GZipOutputStream(outStream, level)) {
					bzipOutput.IsStreamOwner = isStreamOwner;
					Core.StreamUtils.Copy(inStream, bzipOutput, new byte[4096]);
				}
			} finally {
				if (isStreamOwner) {
					// outStream is closed by the GZipOutputStream if stream owner
					inStream.Dispose();
				}
			}
		}

建议修改为

        public static void Compress(Stream inStream, Stream outStream, bool isStreamOwner, int level)
		{
			if (inStream == null || outStream == null) {
				throw new Exception("Null Stream");
			}

			try {
				using (GZipOutputStream bzipOutput = new GZipOutputStream(outStream)) {
					bzipOutput.SetLevel(level);
					bzipOutput.IsStreamOwner = isStreamOwner;
					Core.StreamUtils.Copy(inStream, bzipOutput, new byte[4096]);
				}
			} finally {
				if (isStreamOwner) {
					// outStream is closed by the GZipOutputStream if stream owner
					inStream.Dispose();
				}
			}
		}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions