zoukankan      html  css  js  c++  java
  • Dart: 编码和解码各种存档和压缩格式

    import 'dart:io';
    import 'package:path/path.dart' as p;
    import 'package:path/path.dart';
    import 'package:archive/archive.dart';
    import 'package:archive/archive_io.dart';
    
    var path = p.Context(style: Style.posix);
    final String __filename = Platform.script.path.replaceFirst('/', '');
    final String __dirname = Directory(__filename).parent.path;
    
      // 从磁盘读取Zip文件
      List<int> bytes = File(path.join(__dirname, 'test-a-master.zip')).readAsBytesSync();
    
      // 解码Zip文件
      Archive archive = ZipDecoder().decodeBytes(bytes);
    
      // 将Zip存档的内容解压缩到磁盘
      for (ArchiveFile file in archive) {
        String filename = file.name;
        String decodePath = path.join(__dirname, filename);
        if (file.isFile) {
          List<int> data = file.content;
          File(decodePath)
            ..createSync(recursive: true)
            ..writeAsBytesSync(data);
        } else {
          Directory(decodePath)..create(recursive: true);
        }
      }
    
  • 相关阅读:
    MDX函数
    OLAP + MDX
    AIOps指导
    ES Terms 聚合数据不确定性
    redis初步入门
    java写hadoop全局排序
    [工程技巧]
    python与字符集编码
    转载python2进制打包相关
    转载 大端VS小端
  • 原文地址:https://www.cnblogs.com/ajanuw/p/10915005.html
Copyright © 2011-2022 走看看