1- import zippy/ adler32, zippy/ common, zippy/ crc, zippy/ deflate, zippy/ gzip,
2- zippy/ inflate, zippy/ internal
1+ import zippy/ adler32, zippy/ common, zippy/ crc, zippy/ deflate,
2+ zippy/ gzip, zippy/ inflate, zippy/ internal
3+
4+ when (NimMajor , NimMinor , NimPatch ) >= (1 , 6 , 0 ):
5+ import std/ sysrand
6+ else :
7+ import std/ random, std/ times
38
49export common
510
@@ -18,6 +23,23 @@ proc compress*(
1823 result [0 ] = 31 .char
1924 result [1 ] = 139 .char
2025 result [2 ] = 8 .char
26+ result [3 ] = (1 .uint8 shl 3 ).char # Set the fname flag
27+
28+ block : # https://github.com/guzba/zippy/issues/61
29+ let htbLen =
30+ when (NimMajor , NimMinor , NimPatch ) >= (1 , 6 , 0 ):
31+ var urand: array [1 , uint8 ]
32+ if not urandom (urand):
33+ raise newException (ZippyError , " Failed to generate random number" )
34+ (urand[0 ] mod 26 ).int
35+ else :
36+ let now = getTime ()
37+ var rand = initRand (now.toUnix * 1_000_000_000 + now.nanosecond)
38+ (rand.next () mod 26 ).int # mod the uint first to ensure a positive int
39+ # Add up to 26 characters as the gzip header file name
40+ for i in 0 ..< htbLen:
41+ result .add (97 + i).char
42+ result .add '\0 '
2143
2244 deflate (result , src, len, level)
2345
0 commit comments