function deflateSetDictionary(strm, dictionary) {
  let dictLength = dictionary.length;
  let s;
  let str, n;
  let wrap;
  let avail;
  let next;
  let input;
  let tmpDict;
  if (!strm || !strm.state) {
    return Z_STREAM_ERROR;
  }
  s = strm.state;
  wrap = s.wrap;
  if (wrap === 2 || wrap === 1 && s.status !== INIT_STATE || s.lookahead) {
    return Z_STREAM_ERROR;
  }
  /* when using zlib wrappers, compute Adler-32 for provided dictionary */ if (
    wrap === 1
  ) {
    /* adler32(strm->adler, dictionary, dictLength); */ strm.adler = adler32(
      strm.adler,
      dictionary,
      dictLength,
      0,
    );
  }
  s.wrap = 0; /* avoid computing Adler-32 in read_buf */
  /* if dictionary would fill window, just replace the history */ if (
    dictLength >= s.w_size
  ) {
    if (wrap === 0) {
      /* already empty otherwise */ /*** CLEAR_HASH(s); ***/ zero(s.head); // Fill with NIL (= 0);
      s.strstart = 0;
      s.block_start = 0;
      s.insert = 0;
    }
    /* use the tail */
    // dictionary = dictionary.slice(dictLength - s.w_size);
    tmpDict = new Uint8Array(s.w_size);
    tmpDict.set(dictionary.subarray(dictLength - s.w_size, dictLength), 0);
    dictionary = tmpDict;
    dictLength = s.w_size;
  }
  /* insert dictionary into window and hash */ avail = strm.avail_in;
  next = strm.next_in;
  input = strm.input;
  strm.avail_in = dictLength;
  strm.next_in = 0;
  strm.input = dictionary;
  fill_window(s);
  while (s.lookahead >= MIN_MATCH) {
    str = s.strstart;
    n = s.lookahead - (MIN_MATCH - 1);
    do {
      /* UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]); */ s.ins_h =
        (s.ins_h << s.hash_shift ^ s.window[str + MIN_MATCH - 1]) & s.hash_mask;
      s.prev[str & s.w_mask] = s.head[s.ins_h];
      s.head[s.ins_h] = str;
      str++;
    } while (--n);
    s.strstart = str;
    s.lookahead = MIN_MATCH - 1;
    fill_window(s);
  }
  s.strstart += s.lookahead;
  s.block_start = s.strstart;
  s.insert = s.lookahead;
  s.lookahead = 0;
  s.match_length = s.prev_length = MIN_MATCH - 1;
  s.match_available = 0;
  strm.next_in = next;
  strm.input = input;
  strm.avail_in = avail;
  s.wrap = wrap;
  return Z_OK;
}
/* =========================================================================
 * Initializes the compression dictionary from the given byte
 * sequence without producing any compressed output.
 */
Initializes the compression dictionary from the given byte
sequence without producing any compressed output.
Initializes the compression dictionary from the given byte sequence without producing any compressed output .
function deflateSetDictionary(strm, dictionary) {
  let dictLength = dictionary.length;
  let s;
  let str, n;
  let wrap;
  let avail;
  let next;
  let input;
  let tmpDict;
  if (!strm || !strm.state) {
    return Z_STREAM_ERROR;
  }
  s = strm.state;
  wrap = s.wrap;
  if (wrap === 2 || wrap === 1 && s.status !== INIT_STATE || s.lookahead) {
    return Z_STREAM_ERROR;
  }
   if (
    wrap === 1
  ) {
     strm.adler = adler32(
      strm.adler,
      dictionary,
      dictLength,
      0,
    );
  }
  s.wrap = 0; 
   if (
    dictLength >= s.w_size
  ) {
    if (wrap === 0) {
        zero(s.head); 
      s.strstart = 0;
      s.block_start = 0;
      s.insert = 0;
    }
    tmpDict = new Uint8Array(s.w_size);
    tmpDict.set(dictionary.subarray(dictLength - s.w_size, dictLength), 0);
    dictionary = tmpDict;
    dictLength = s.w_size;
  }
   avail = strm.avail_in;
  next = strm.next_in;
  input = strm.input;
  strm.avail_in = dictLength;
  strm.next_in = 0;
  strm.input = dictionary;
  fill_window(s);
  while (s.lookahead >= MIN_MATCH) {
    str = s.strstart;
    n = s.lookahead - (MIN_MATCH - 1);
    do {
       s.ins_h =
        (s.ins_h << s.hash_shift ^ s.window[str + MIN_MATCH - 1]) & s.hash_mask;
      s.prev[str & s.w_mask] = s.head[s.ins_h];
      s.head[s.ins_h] = str;
      str++;
    } while (--n);
    s.strstart = str;
    s.lookahead = MIN_MATCH - 1;
    fill_window(s);
  }
  s.strstart += s.lookahead;
  s.block_start = s.strstart;
  s.insert = s.lookahead;
  s.lookahead = 0;
  s.match_length = s.prev_length = MIN_MATCH - 1;
  s.match_available = 0;
  strm.next_in = next;
  strm.input = input;
  strm.avail_in = avail;
  s.wrap = wrap;
  return Z_OK;
}
function deflateSetDictionary ( strm , dictionary ) { let dictLength = dictionary . length ; let s ; let str , n ; let wrap ; let avail ; let next ; let input ; let tmpDict ; if ( ! strm || ! strm . state ) { return Z_STREAM_ERROR ; } s = strm . state ; wrap = s . wrap ; if ( wrap === 2 || wrap === 1 && s . status !== INIT_STATE || s . lookahead ) { return Z_STREAM_ERROR ; } if ( wrap === 1 ) { strm . adler = adler32 ( strm . adler , dictionary , dictLength , 0 , ) ; } s . wrap = 0 ; if ( dictLength >= s . w_size ) { if ( wrap === 0 ) { zero ( s . head ) ; s . strstart = 0 ; s . block_start = 0 ; s . insert = 0 ; } tmpDict = new Uint8Array ( s . w_size ) ; tmpDict . set ( dictionary . subarray ( dictLength - s . w_size , dictLength ) , 0 ) ; dictionary = tmpDict ; dictLength = s . w_size ; } avail = strm . avail_in ; next = strm . next_in ; input = strm . input ; strm . avail_in = dictLength ; strm . next_in = 0 ; strm . input = dictionary ; fill_window ( s ) ; while ( s . lookahead >= MIN_MATCH ) { str = s . strstart ; n = s . lookahead - ( MIN_MATCH - 1 ) ; do { s . ins_h = ( s . ins_h << s . hash_shift ^ s . window [ str + MIN_MATCH - 1 ] ) & s . hash_mask ; s . prev [ str & s . w_mask ] = s . head [ s . ins_h ] ; s . head [ s . ins_h ] = str ; str ++ ; } while ( -- n ) ; s . strstart = str ; s . lookahead = MIN_MATCH - 1 ; fill_window ( s ) ; } s . strstart += s . lookahead ; s . block_start = s . strstart ; s . insert = s . lookahead ; s . lookahead = 0 ; s . match_length = s . prev_length = MIN_MATCH - 1 ; s . match_available = 0 ; strm . next_in = next ; strm . input = input ; strm . avail_in = avail ; s . wrap = wrap ; return Z_OK ; }
Initializes the compression dictionary from the given byte
 sequence without producing any compressed output.
Initializes the compression dictionary from the given byte sequence without producing any compressed output .
/* when using zlib wrappers, compute Adler-32 for provided dictionary */ /* adler32(strm->adler, dictionary, dictLength); */ /* avoid computing Adler-32 in read_buf */ /* if dictionary would fill window, just replace the history */ /* already empty otherwise */ /*** CLEAR_HASH(s); ***/ // Fill with NIL (= 0); /* use the tail */ // dictionary = dictionary.slice(dictLength - s.w_size); /* insert dictionary into window and hash */ /* UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]); */