Skip to content

Instantly share code, notes, and snippets.

@kmahyyg
Created August 2, 2024 05:26
Show Gist options
  • Save kmahyyg/537a503be7a4aaa9c85cbbbd2f4ee4e8 to your computer and use it in GitHub Desktop.
Save kmahyyg/537a503be7a4aaa9c85cbbbd2f4ee4e8 to your computer and use it in GitHub Desktop.
NSON JSON Converter
package main
import (
"compress/flate"
"flag"
"io"
"log"
"os"
"strings"
)
func main() {
// Define command line flags
input := flag.String("i", "", "Input file path")
output := flag.String("o", "", "Output file path")
flag.Parse()
// Check if input and output are provided
if *input == "" || *output == "" {
log.Println("Input and output file paths are required")
os.Exit(1)
}
// Determine mode based on the file extension
mode := "compress"
if strings.HasSuffix(*input, ".nson") {
mode = "decompress"
}
// Open input file
inputFile, err := os.Open(*input)
if err != nil {
log.Printf("Failed to open input file: %s\n", err)
os.Exit(1)
}
defer inputFile.Close()
// Create output file
outputFile, err := os.Create(*output)
if err != nil {
log.Printf("Failed to create output file: %s\n", err)
os.Exit(1)
}
defer outputFile.Close()
// Set up flate writer or reader
var stream io.ReadCloser
var w io.WriteCloser
if mode == "compress" {
w, err = flate.NewWriter(outputFile, flate.DefaultCompression)
if err != nil {
log.Printf("Failed to create flate writer: %s\n", err)
os.Exit(1)
}
defer w.Close()
} else {
stream = flate.NewReader(inputFile)
defer stream.Close()
}
// Perform the compression or decompression
if mode == "compress" {
_, err = io.Copy(w, inputFile)
} else {
_, err = io.Copy(outputFile, stream)
}
if err != nil {
log.Printf("Failed to process data: %s\n", err)
os.Exit(1)
}
log.Println("Operation completed successfully.")
}
@kmahyyg
Copy link
Author

kmahyyg commented Aug 2, 2024

This is used to convert NaniNovel game save from NSON format to JSON format and verse vesa.
Can be compiled on go version go1.22.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment