github.com/keybase/client/go@v0.0.0-20240309051027-028f7c731f8b/uidmap/data/mkdata.iced (about) 1 {Gets} = require('iced-utils') 2 {make_esc} = require 'iced-error' 3 zlib = require 'zlib' 4 5 gojoin = (v) -> v.join(", ") + "," 6 7 uid_to_byte_list = (uid) -> gojoin ("0x" + uid[i...(i+2)] for i in [0...uid.length] by 2) 8 9 hexbyte = (b) -> 10 s = b.toString(16) 11 if b < 16 then s = "0" + s 12 "0x#{s}" 13 14 class Runner 15 16 constructor : () -> 17 map = [] 18 19 read : ({input}, cb) -> 20 esc = make_esc cb, "read" 21 gets = (new Gets input).run() 22 map = [] 23 loop 24 await gets.gets esc defer line 25 break unless line? 26 [uid,username] = line.split /\s+/ 27 map.push [ uid, username ] 28 cb null, map 29 30 output : ({map}, cb) -> 31 out = [] 32 out.push "package uidmap" 33 out.push '' 34 @output_uid_list { map, out } 35 out.push '' 36 @output_username_block { map, out } 37 out.push '' 38 @output_lengths { map, out } 39 out.join "\n" 40 41 output_username_block : ({map, out}) -> 42 block = (username for [_,username] in map).join('').toLowerCase() 43 zipped = zlib.deflateSync(new Buffer block, 'utf8') 44 out.push "const usernamesLen = " + block.length 45 out.push "var usernamesCompressed = [...]byte{" 46 for i in [0...zipped.length] by 16 47 bytes = zipped[i...(i+16)] 48 out.push "\t" + gojoin (hexbyte(b) for b in bytes) 49 out.push "}" 50 51 output_lengths : ({map, out}) -> 52 out.push "var lengths = [...]uint8{" 53 offset = 0 54 for i in [0...map.length] by 16 55 v = for [_,username] in map[i...(i+16)] 56 username.length.toString 10 57 out.push "\t" + gojoin v 58 out.push "}" 59 60 output_uid_list : ({map, out}) -> 61 out.push "var uids = [...]byte{" 62 for [uid] in map 63 out.push "\t" + uid_to_byte_list(uid) 64 out.push "}" 65 66 run : ({input}, cb) -> 67 esc = make_esc cb, "run" 68 await @read { input }, esc defer map 69 out = @output { map } 70 console.log out 71 cb null 72 73 r = new Runner 74 await r.run { input : process.stdin }, defer err 75 rc = 0 76 if err? 77 console.err err.toString() 78 rc = -2 79 process.exit rc