1
0
Fork 0
mirror of https://github.com/anyproto/anytype-heart.git synced 2025-06-08 05:47:07 +09:00

GO-1890 Add docs

This commit is contained in:
kirillston 2023-09-25 17:24:32 +02:00
parent 6eb222555d
commit 898f3243e4
No known key found for this signature in database
GPG key ID: 88218A7F1109754B
3 changed files with 39 additions and 8 deletions

View file

@ -13,6 +13,10 @@ Current main branch doesn't work with the production any-sync nodes. For now, yo
- [Style guide](docs/Codestyle.md)
- [Project workflows](docs/Flow.md)
### CLI tools
- [Archive processor](cmd/archiveprocessor/README.md)
- [Archive converter](cmd/archiveconverter/README.md)
## Contribution
Thank you for your desire to develop Anytype together!

View file

@ -0,0 +1,29 @@
## Exported archives converter tool
Anytype allows user to export desired objects whether in _JSON_ or _PROTOBUF_ formats.
Most of exported archives contain objects stored in _PROTOBUF_ format, as it is encoded and lightweight. However, if you need to convert an exported archive to see all objects in _JSON_ format you can use **archiveconverter** tool.
CLI can run in two modes.
### Unpack
```bash
go run main.go -unpack <path_to_zip>
```
`unpack` parameter accepts path to the _ZIP_ archive containing _PROTOBUF_ files. Each file should be one of following model:
- ChangeSnapshot
- SnapshotWithType
- Profile
As a result program generates a directory with files in _JSON_ format corresponding to content of input archive.
You can edit it freely.
### Pack
```bash
go run main.go -pack <path_to_directory>
```
`pack` parameter accepts path to the directory containing _JSON_ files, that also should be one of models presented in previous paragraph.
In packing mode program does reverse operation and creates an archive with _PROTOBUF_ files corresponding to _JSON_ objects presented in input directory.

View file

@ -26,7 +26,6 @@ func main() {
// command line flags
unpack := flag.String("unpack", "", "Unpack zip archive with pb files to the directory with json files")
pack := flag.String("pack", "", "Convert json files in a directory to pb and write to a zip file")
useTypedSnapshot := flag.Bool("snapshotWithType", false, "If true, SnapshotWithType is used instead of ChangeSnapshot")
flag.Parse()
@ -36,7 +35,7 @@ func main() {
}
if *pack != "" {
createZipFromDirectory(*pack, *pack+".zip", *useTypedSnapshot)
createZipFromDirectory(*pack, *pack+".zip")
return
}
@ -174,7 +173,7 @@ func handleDirectory(input, output string) {
}
}
func createZipFromDirectory(input, output string, useTypedSnapshot bool) {
func createZipFromDirectory(input, output string) {
// create a new zip file
newZipFile, err := os.Create(output)
if err != nil {
@ -209,14 +208,13 @@ func createZipFromDirectory(input, output string, useTypedSnapshot bool) {
if isProfile {
snapshot = &pb.Profile{}
}
if useTypedSnapshot {
fmt.Printf("wabada")
snapshot = &pb.SnapshotWithType{}
}
err = jsonpb.UnmarshalString(string(data), snapshot)
if err != nil {
return err
snapshot = &pb.SnapshotWithType{}
if err = jsonpb.UnmarshalString(string(data), snapshot); err != nil {
return err
}
}
pbData, err := proto.Marshal(snapshot)