go-hep.org/x/hep@v0.38.1/groot/riofs/compress.go (about)

     1  // Copyright ©2018 The go-hep Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package riofs
     6  
     7  import (
     8  	"go-hep.org/x/hep/groot/internal/rcompress"
     9  )
    10  
    11  func (f *File) setCompression(alg rcompress.Kind, lvl int) {
    12  	f.compression = rcompress.Settings{Alg: alg, Lvl: lvl}.Compression()
    13  }
    14  
    15  // WithLZ4 configures a ROOT file to use LZ4 as a compression mechanism.
    16  func WithLZ4(level int) FileOption {
    17  	return func(f *File) error {
    18  		f.setCompression(rcompress.LZ4, level)
    19  		return nil
    20  	}
    21  }
    22  
    23  // WithLZMA configures a ROOT file to use LZMA as a compression mechanism.
    24  func WithLZMA(level int) FileOption {
    25  	return func(f *File) error {
    26  		f.setCompression(rcompress.LZMA, level)
    27  		return nil
    28  	}
    29  }
    30  
    31  // WithoutCompression configures a ROOT file to not use any compression mechanism.
    32  func WithoutCompression() FileOption {
    33  	return func(f *File) error {
    34  		f.setCompression(0, 0)
    35  		return nil
    36  	}
    37  }
    38  
    39  // WithZlib configures a ROOT file to use zlib as a compression mechanism.
    40  func WithZlib(level int) FileOption {
    41  	return func(f *File) error {
    42  		f.setCompression(rcompress.ZLIB, level)
    43  		return nil
    44  	}
    45  }
    46  
    47  // WithZstd configures a ROOT file to use zstd as a compression mechanism.
    48  func WithZstd(level int) FileOption {
    49  	return func(f *File) error {
    50  		f.setCompression(rcompress.ZSTD, level)
    51  		return nil
    52  	}
    53  }