Giter Site home page Giter Site logo

compress_youtube's Introduction

compress_youtube

将一个文件压缩为gzip格式

代码步骤如下

  1. 检查命令行参数的数量,如果不是3个,则打印错误信息并返回。
  2. 使用 BufReader 打开第一个命令行参数指定的文件,并将其赋值给 input 变量。如果文件打开失败,会产生一个错误。
  3. 创建一个新的文件,用于存储压缩后的数据,并将其赋值给 output 变量。如果文件创建失败,会产生一个错误。
  4. 创建一个 GzEncoder 对象,将 output 作为输出流,并使用默认的压缩级别。将该对象赋值给 encoder 变量。
  5. 使用 Instant 记录当前时间,并将其赋值给 start 变量。
  6. input 的数据复制到 encoder 中,实现文件的压缩。如果复制过程中发生错误,会产生一个错误。
  7. 调用 encoderfinish 方法,完成压缩过程,并将结果赋值给 output 变量。
  8. 打印原始文件的长度,使用 input.get_ref().metadata().unwrap().len() 获取原始文件的元数据,并打印其长度。
  9. 打印压缩后文件的长度,使用 output.metadata().unwrap().len() 获取压缩后文件的元数据,并打印其长度。
  10. 打印程序执行的时间,使用 start.elapsed() 获取程序执行的时间,并打印出来。

compress_youtube's People

Contributors

qiaopengjun5162 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.