Line data Source code
1 : // Copyright 2024 The LevelDB-Go and Pebble Authors. All rights reserved. Use 2 : // of this source code is governed by a BSD-style license that can be found in 3 : // the LICENSE file. 4 : 5 : package lsmview 6 : 7 : import ( 8 : "bytes" 9 : "compress/zlib" 10 : "encoding/base64" 11 : "encoding/json" 12 : "net/url" 13 : ) 14 : 15 : // GenerateURL generates a URL showing the LSM diagram. The URL contains the 16 : // encoded and compressed data as the URL fragment. 17 0 : func GenerateURL(data Data) (url.URL, error) { 18 0 : var jsonBuf bytes.Buffer 19 0 : if err := json.NewEncoder(&jsonBuf).Encode(data); err != nil { 20 0 : return url.URL{}, err 21 0 : } 22 : 23 0 : var compressed bytes.Buffer 24 0 : encoder := base64.NewEncoder(base64.URLEncoding, &compressed) 25 0 : compressor := zlib.NewWriter(encoder) 26 0 : if _, err := jsonBuf.WriteTo(compressor); err != nil { 27 0 : return url.URL{}, err 28 0 : } 29 0 : if err := compressor.Close(); err != nil { 30 0 : return url.URL{}, err 31 0 : } 32 0 : if err := encoder.Close(); err != nil { 33 0 : return url.URL{}, err 34 0 : } 35 0 : return url.URL{ 36 0 : Scheme: "https", 37 0 : Host: "raduberinde.github.io", 38 0 : Path: "lsmview/decode.html", 39 0 : Fragment: compressed.String(), 40 0 : }, nil 41 : }