- 
                Notifications
    
You must be signed in to change notification settings  - Fork 30
 
Implement the xz Delta filter (filter 3) #101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Open
      
      
            terrence2
  wants to merge
  10
  commits into
  gendx:master
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
terrence2:delta-filter-3
  
      
      
   
  
    
  
  
  
 
  
      
    base: master
Could not load branches
            
              
  
    Branch not found: {{ refName }}
  
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
            
                
      Loading
              
            Are you sure you want to change the base?
            Some commits from the old base branch may be removed from the timeline,
            and old review comments may become outdated.
          
          
  
     Open
                    Changes from 4 commits
      Commits
    
    
            Show all changes
          
          
            10 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      8b7fc8b
              
                Add a failing test case for filter mode 3
              
              
                terrence2 fe5dba2
              
                Initial implementation of delta compression
              
              
                terrence2 3a678d8
              
                Fix a comment and format
              
              
                terrence2 dd0e71b
              
                Run clippy
              
              
                terrence2 b7778af
              
                No need to create a temp vector to iterate
              
              
                terrence2 ad64eb2
              
                Document default tmpbuf block size
              
              
                terrence2 6183343
              
                Comment on invariant in num_filters at usage site
              
              
                terrence2 b1bef96
              
                Use wrapping and a smarter traveral order
              
              
                terrence2 86368f0
              
                Use the new fs::read function
              
              
                terrence2 7e49d98
              
                Test the test cases with the reference decoder
              
              
                terrence2 File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| use crate::decode::lzbuffer; | ||
| use crate::decode::lzbuffer::LzBuffer; | ||
| use crate::error; | ||
| use byteorder::ReadBytesExt; | ||
| use std::io; | ||
| 
     | 
||
| #[derive(Debug)] | ||
| /// Decoder for XZ delta-encoded blocks (filter 3). | ||
| pub struct DeltaDecoder { | ||
| distance: usize, | ||
| pos: u8, | ||
| delta: [u8; 256], | ||
| } | ||
| 
     | 
||
| impl DeltaDecoder { | ||
| /// Creates a new object ready for transforming data that it's given. | ||
| pub fn new(property_distance: u8) -> Self { | ||
| DeltaDecoder { | ||
| distance: property_distance as usize + 1, | ||
| pos: 0, | ||
| delta: [0u8; 256], | ||
| } | ||
| } | ||
| 
     | 
||
| /// Performs the equivalent of replacing this decompression state with a | ||
| /// freshly allocated copy. | ||
| /// | ||
| /// This function may not allocate memory and will attempt to reuse any | ||
| /// previously allocated resources. | ||
| #[cfg(feature = "raw_decoder")] | ||
| pub fn reset(&mut self) { | ||
| self.pos = 0; | ||
| self.delta = [0u8; 256]; | ||
| } | ||
| 
     | 
||
| /// Decompresses the input data into the output, consuming only as much | ||
| /// input as needed and writing as much output as possible. | ||
| pub fn decompress<W: io::Write, R: io::BufRead>( | ||
| &mut self, | ||
| input: &mut R, | ||
| output: &mut W, | ||
| ) -> error::Result<()> { | ||
| let mut accum = lzbuffer::LzAccumBuffer::from_stream(output, usize::MAX); | ||
| 
     | 
||
| // See xz-file-format.txt for the C pseudocode this is implementing. | ||
| loop { | ||
| let byte = if let Ok(byte) = input.read_u8() { | ||
| byte | ||
| } else { | ||
| lzma_info!("Delta end of input"); | ||
| break; | ||
| }; | ||
| 
     | 
||
| let tmp = self.delta[(self.distance + self.pos as usize) as u8 as usize]; | ||
| let tmp = byte.wrapping_add(tmp); | ||
| self.delta[self.pos as usize] = tmp; | ||
| 
     | 
||
| accum.append_literal(tmp)?; | ||
| self.pos = self.pos.wrapping_sub(1); | ||
                
      
                  terrence2 marked this conversation as resolved.
               
              
                Outdated
          
            Show resolved
            Hide resolved
         | 
||
| } | ||
| 
     | 
||
| accum.finish()?; | ||
| Ok(()) | ||
| } | ||
| } | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| //! Decoding logic. | ||
| 
     | 
||
| pub mod delta; | ||
| pub mod lzbuffer; | ||
| pub mod lzma; | ||
| pub mod lzma2; | ||
| 
          
            
          
           | 
    ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
            Binary file not shown.
          
    
                              
      
                  terrence2 marked this conversation as resolved.
               
          
            Show resolved
            Hide resolved
         | 
            
            Binary file not shown.
          
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.