<commit_before>#[cfg(target_family="unix")]
extern crate lzma;
extern crate zip;

use std::fs::{File, metadata};
use std::io::{Read, Seek, Write};
use zip::read::{ZipArchive, ZipFile};
use zip::result::ZipResult;
use zip::write::{FileOptions, ZipWriter};

#[cfg(target_family="unix")]
use lzma::{LzmaWriter, LzmaError};

static FILE_CONTENTS: &'static [u8] = include_bytes!("../Cargo.lock");

fn create_zip_archive<T: Seek + Write>(buf: &mut T) -> ZipResult<()> {
    let mut writer = ZipWriter::new(buf);
    writer.start_file("example.txt", FileOptions::default())?;
    writer.write(FILE_CONTENTS)?;
    writer.finish()?;
    Ok(())
}

fn browse_zip_archive<T, F, U>(buf: &mut T, browse_func: F) -> ZipResult<Vec<U>>
    where T: Read + Seek,
          F: Fn(&ZipFile) -> ZipResult<U>
{
    let mut archive = ZipArchive::new(buf)?;
    (0..archive.len())
        .map(|i| archive.by_index(i).and_then(|file| browse_func(&file)))
        .collect()
}

fn create_bz2_archive<T: Seek + Write>(buf: &mut T) -> ZipResult<()> {
    let mut writer = ZipWriter::new(buf);
    writer.start_file("example.txt",
                    FileOptions::default().compression_method(zip::CompressionMethod::Bzip2))?;
    writer.write(FILE_CONTENTS)?;
    writer.finish()?;
    Ok(())
}

#[cfg(target_family="unix")]
fn create_xz_archive<T: Write>(buf: &mut T) -> Result<(), LzmaError> {
    let mut writer = LzmaWriter::new_compressor(buf, 6)?;
    writer.write(FILE_CONTENTS)?;
    writer.finish()?;
    Ok(())
}

#[cfg(target_family="windows")]<commit_msg>Use write_all in archive examples.<commit_after>#[cfg(target_family="unix")]
extern crate lzma;
extern crate zip;

use std::fs::{File, metadata};
use std::io::{Read, Seek, Write};
use zip::read::{ZipArchive, ZipFile};
use zip::result::ZipResult;
use zip::write::{FileOptions, ZipWriter};

#[cfg(target_family="unix")]
use lzma::{LzmaWriter, LzmaError};

static FILE_CONTENTS: &'static [u8] = include_bytes!("../Cargo.lock");

fn create_zip_archive<T: Seek + Write>(buf: &mut T) -> ZipResult<()> {
    let mut writer = ZipWriter::new(buf);
    writer.start_file("example.txt", FileOptions::default())?;
    writer.write_all(FILE_CONTENTS)?;
    writer.finish()?;
    Ok(())
}

fn browse_zip_archive<T, F, U>(buf: &mut T, browse_func: F) -> ZipResult<Vec<U>>
    where T: Read + Seek,
          F: Fn(&ZipFile) -> ZipResult<U>
{
    let mut archive = ZipArchive::new(buf)?;
    (0..archive.len())
        .map(|i| archive.by_index(i).and_then(|file| browse_func(&file)))
        .collect()
}

fn create_bz2_archive<T: Seek + Write>(buf: &mut T) -> ZipResult<()> {
    let mut writer = ZipWriter::new(buf);
    writer.start_file("example.txt",
                    FileOptions::default().compression_method(zip::CompressionMethod::Bzip2))?;
    writer.write_all(FILE_CONTENTS)?;
    writer.finish()?;
    Ok(())
}

#[cfg(target_family="unix")]
fn create_xz_archive<T: Write>(buf: &mut T) -> Result<(), LzmaError> {
    let mut writer = LzmaWriter::new_compressor(buf, 6)?;
    writer.write_all(FILE_CONTENTS)?;
    writer.finish()?;
    Ok(())
}

#[cfg(target_family="windows")]
{'fraction_non_alphanumeric': 0.1942215088282504, 'fraction_numerical': 0.0032102728731942215, 'mean_word_length': 4.624548736462094, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6392021', 'n_tokens_mistral': 1155, 'n_tokens_neox': 1138, 'n_words': 213}