@@ -29,11 +29,12 @@ class FileOutput < Output
29
29
30
30
helpers :formatter , :inject , :compat_parameters
31
31
32
- SUPPORTED_COMPRESS = [ :text , :gz , :gzip ]
32
+ SUPPORTED_COMPRESS = [ :text , :gz , :gzip , :zstd ]
33
33
SUPPORTED_COMPRESS_MAP = {
34
34
text : nil ,
35
35
gz : :gzip ,
36
36
gzip : :gzip ,
37
+ zstd : :zstd ,
37
38
}
38
39
39
40
DEFAULT_TIMEKEY = 60 * 60 * 24
@@ -212,17 +213,27 @@ def write(chunk)
212
213
FileUtils . mkdir_p File . dirname ( path ) , mode : @dir_perm
213
214
214
215
writer = case
215
- when @compress_method . nil?
216
- method ( :write_without_compression )
217
- when @compress_method == :gzip
218
- if @buffer . compress != :gzip || @recompress
219
- method ( :write_gzip_with_compression )
220
- else
221
- method ( :write_gzip_from_gzipped_chunk )
222
- end
223
- else
224
- raise "BUG: unknown compression method #{ @compress_method } "
225
- end
216
+ when @compress_method . nil?
217
+ method ( :write_without_compression )
218
+ when @compress_method == :gzip
219
+ if @buffer . compress == :text || @recompress
220
+ method ( :write_with_compression ) . curry . call ( @compress_method )
221
+ elsif @buffer . compress == :gzip
222
+ method ( :write_from_compressed_chunk ) . curry . call ( @compress_method )
223
+ else
224
+ raise Fluent ::ConfigError , "You cannot specify different compression formats for Buffer (Buffer: #{ @buffer . compress } , Self: #{ @compress } )"
225
+ end
226
+ when @compress_method == :zstd
227
+ if @buffer . compress == :text || @recompress
228
+ method ( :write_with_compression ) . curry . call ( @compress_method )
229
+ elsif @buffer . compress == :zstd
230
+ method ( :write_from_compressed_chunk ) . curry . call ( @compress_method )
231
+ else
232
+ raise Fluent ::ConfigError , "You cannot specify different compression formats for Buffer (Buffer: #{ @buffer . compress } , Self: #{ @compress } )"
233
+ end
234
+ else
235
+ raise "BUG: unknown compression method #{ @compress_method } "
236
+ end
226
237
227
238
if @append
228
239
if @need_lock
@@ -253,17 +264,22 @@ def write_without_compression(path, chunk)
253
264
end
254
265
end
255
266
256
- def write_gzip_with_compression ( path , chunk )
267
+ def write_with_compression ( type , path , chunk )
257
268
File . open ( path , "ab" , @file_perm ) do |f |
258
- gz = Zlib ::GzipWriter . new ( f )
269
+ gz = nil
270
+ if type == :gzip
271
+ gz = Zlib ::GzipWriter . new ( f )
272
+ elsif type == :zstd
273
+ gz = Zstd ::StreamWriter . new ( f )
274
+ end
259
275
chunk . write_to ( gz , compressed : :text )
260
276
gz . close
261
277
end
262
278
end
263
279
264
- def write_gzip_from_gzipped_chunk ( path , chunk )
280
+ def write_from_compressed_chunk ( type , path , chunk )
265
281
File . open ( path , "ab" , @file_perm ) do |f |
266
- chunk . write_to ( f , compressed : :gzip )
282
+ chunk . write_to ( f , compressed : type )
267
283
end
268
284
end
269
285
@@ -280,6 +296,7 @@ def timekey_to_timeformat(timekey)
280
296
def compression_suffix ( compress )
281
297
case compress
282
298
when :gzip then '.gz'
299
+ when :zstd then '.zstd'
283
300
when nil then ''
284
301
else
285
302
raise ArgumentError , "unknown compression type #{ compress } "
0 commit comments