如何压缩字符串? [英] How to zip a string?

查看:52
本文介绍了如何压缩字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个类在python中的等价物是什么?https://gist.github.com/2594962

What is the equivalent of this class in python? https://gist.github.com/2594962

在 PHP 中,它允许您压缩字符串.

In PHP, it allows you to zip a string.

我正在尝试寻找以下语言的等效项:Python、Ruby on Rails 和 ASP.

I'm trying to find the equivaelnt in the following languages: Python, Ruby on Rails and ASP.

我希望有这些语言的内置函数.我在 PHP 中找不到.

I'm hoping there are built in functions for these languages. I couldn't find one in PHP.

当我说 Zip 时,我指的是 Windows 使用的标准算法.不是存档意义上的.我目前使用该类来压缩字符串,对其进行 base64 编码并将其作为请求发送到内部 API.

When I say Zip, I am referring to the standard algorithm that windows uses. Not in the sense of an archive. I currently use that class to zip a string, base64 encode it and send it as a request to an internal API.

推荐答案

在 Python 下,您正在寻找 zipfile 模块 - 特别是 ZipFile.writestr().

Under Python, you are looking for the zipfile module - specifically ZipFile.writestr().

我注意到一般来说,zlib 用于您所谈论的那种用途.

I'd note that in general, zlib is used a lot more for the kind of uses you are talking about.

这篇关于如何压缩字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆