LCOV - code coverage report
Current view: top level - pebble/internal/lsmview - url.go (source / functions) Hit Total Coverage
Test: 2024-03-30 08:16Z 1c7bcd1c - tests + meta.lcov Lines: 15 23 65.2 %
Date: 2024-03-30 08:17:45 Functions: 0 0 -

          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           1 : func GenerateURL(data Data) (url.URL, error) {
      18           1 :         var jsonBuf bytes.Buffer
      19           1 :         if err := json.NewEncoder(&jsonBuf).Encode(data); err != nil {
      20           0 :                 return url.URL{}, err
      21           0 :         }
      22             : 
      23           1 :         var compressed bytes.Buffer
      24           1 :         encoder := base64.NewEncoder(base64.URLEncoding, &compressed)
      25           1 :         compressor := zlib.NewWriter(encoder)
      26           1 :         if _, err := jsonBuf.WriteTo(compressor); err != nil {
      27           0 :                 return url.URL{}, err
      28           0 :         }
      29           1 :         if err := compressor.Close(); err != nil {
      30           0 :                 return url.URL{}, err
      31           0 :         }
      32           1 :         if err := encoder.Close(); err != nil {
      33           0 :                 return url.URL{}, err
      34           0 :         }
      35           1 :         return url.URL{
      36           1 :                 Scheme:   "https",
      37           1 :                 Host:     "raduberinde.github.io",
      38           1 :                 Path:     "lsmview/decode.html",
      39           1 :                 Fragment: compressed.String(),
      40           1 :         }, nil
      41             : }

Generated by: LCOV version 1.14