mirror of
https://github.com/PeernetOfficial/core.git
synced 2026-07-23 05:07:51 +01:00
Rename Directory to Folder to make more sense.
Introduce new file type TypeFolder which is not used anywhere, however.
This commit is contained in:
@@ -82,18 +82,19 @@ type BlockRecordFileTag struct {
|
|||||||
|
|
||||||
// TagTypeName defines the type of the tag
|
// TagTypeName defines the type of the tag
|
||||||
const (
|
const (
|
||||||
TagTypeName = 0 // File name
|
TagTypeName = 0 // Name of file
|
||||||
TagTypeDirectory = 1 // Directory
|
TagTypeFolder = 1 // Folder
|
||||||
TagTypeDateCreated = 2 // Date when the file was originally created. This may differ from the date in the block record, which indicates when the file was shared.
|
TagTypeDateCreated = 2 // Date when the file was originally created. This may differ from the date in the block record, which indicates when the file was shared.
|
||||||
TagTypeDescription = 3 // Arbitrary description of the file. May contain hashtags.
|
TagTypeDescription = 3 // Arbitrary description of the file. May contain hashtags.
|
||||||
)
|
)
|
||||||
|
|
||||||
// FileTagDirectory specifies in which directory the file is stored
|
// FileTagFolder specifies in which folder the file is stored.
|
||||||
type FileTagDirectory struct {
|
// A corresponding TypeFolder file record matching the name may exist to provide additional details about the folder.
|
||||||
Directory string // Directory the file is stored at
|
type FileTagFolder struct {
|
||||||
|
Name string // Name of the folder
|
||||||
}
|
}
|
||||||
|
|
||||||
// FileTagName specifies in which directory the file is stored
|
// FileTagName specifies the file name. Empty names are allowed, but not recommended!
|
||||||
type FileTagName struct {
|
type FileTagName struct {
|
||||||
Name string // Name of the file
|
Name string // Name of the file
|
||||||
}
|
}
|
||||||
@@ -208,8 +209,8 @@ func decodeBlockRecordFiles(recordsRaw []BlockRecordRaw) (files []BlockRecordFil
|
|||||||
// decodeFileTag decodes a file tag. If the tag type is not known, it returns nil.
|
// decodeFileTag decodes a file tag. If the tag type is not known, it returns nil.
|
||||||
func decodeFileTag(tag BlockRecordFileTag) (decoded interface{}, err error) {
|
func decodeFileTag(tag BlockRecordFileTag) (decoded interface{}, err error) {
|
||||||
switch tag.Type {
|
switch tag.Type {
|
||||||
case TagTypeDirectory:
|
case TagTypeFolder:
|
||||||
return FileTagDirectory{Directory: string(tag.Data)}, nil
|
return FileTagFolder{Name: string(tag.Data)}, nil
|
||||||
|
|
||||||
case TagTypeName:
|
case TagTypeName:
|
||||||
return FileTagName{Name: string(tag.Data)}, nil
|
return FileTagName{Name: string(tag.Data)}, nil
|
||||||
@@ -233,8 +234,8 @@ func decodeFileTag(tag BlockRecordFileTag) (decoded interface{}, err error) {
|
|||||||
// encodeFileTag encodes a file tag. If the tag type is not known, it returns nil.
|
// encodeFileTag encodes a file tag. If the tag type is not known, it returns nil.
|
||||||
func encodeFileTag(decoded interface{}) (tag BlockRecordFileTag, err error) {
|
func encodeFileTag(decoded interface{}) (tag BlockRecordFileTag, err error) {
|
||||||
switch v := decoded.(type) {
|
switch v := decoded.(type) {
|
||||||
case FileTagDirectory:
|
case FileTagFolder:
|
||||||
return BlockRecordFileTag{Type: TagTypeDirectory, Data: []byte(v.Directory)}, nil
|
return BlockRecordFileTag{Type: TagTypeFolder, Data: []byte(v.Name)}, nil
|
||||||
|
|
||||||
case FileTagName:
|
case FileTagName:
|
||||||
return BlockRecordFileTag{Type: TagTypeName, Data: []byte(v.Name)}, nil
|
return BlockRecordFileTag{Type: TagTypeName, Data: []byte(v.Name)}, nil
|
||||||
@@ -253,7 +254,8 @@ func encodeFileTag(decoded interface{}) (tag BlockRecordFileTag, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// encodeBlockRecordFiles encodes files into the block record data
|
// encodeBlockRecordFiles encodes files into the block record data
|
||||||
// This function should be called grouped with all files in the same directory. The directory name is deduplicated; only unique directory records will be returned.
|
// This function should be called grouped with all files in the same folder. The folder name is deduplicated; only unique folder records will be returned.
|
||||||
|
// Note that this function only stores the folder names as tags; it does not create separate TypeFolder file records.
|
||||||
func encodeBlockRecordFiles(files []BlockRecordFile) (recordsRaw []BlockRecordRaw, err error) {
|
func encodeBlockRecordFiles(files []BlockRecordFile) (recordsRaw []BlockRecordRaw, err error) {
|
||||||
uniqueTagDataMap := make(map[string]struct{})
|
uniqueTagDataMap := make(map[string]struct{})
|
||||||
duplicateTagDataMap := make(map[string]int) // list of tag data that appeared twice. Number in recordsRaw.
|
duplicateTagDataMap := make(map[string]int) // list of tag data that appeared twice. Number in recordsRaw.
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ const (
|
|||||||
TypeExecutable // Any executable file, OS independent
|
TypeExecutable // Any executable file, OS independent
|
||||||
TypeContainer // Container files like ZIP, RAR, TAR
|
TypeContainer // Container files like ZIP, RAR, TAR
|
||||||
TypeCompressed // Compressed files like GZ, BZ
|
TypeCompressed // Compressed files like GZ, BZ
|
||||||
|
TypeFolder // Virtual folder
|
||||||
)
|
)
|
||||||
|
|
||||||
// High-level file types. New ones may be added as required.
|
// High-level file types. New ones may be added as required.
|
||||||
@@ -39,6 +40,7 @@ const (
|
|||||||
FormatDatabase // Database file
|
FormatDatabase // Database file
|
||||||
FormatEmail // Single email
|
FormatEmail // Single email
|
||||||
FormatCSV // CSV file
|
FormatCSV // CSV file
|
||||||
|
FormatFolder // Virtual folder
|
||||||
)
|
)
|
||||||
|
|
||||||
// Future tags to be defined for audio/video: Artist, Album, Title, Length, Bitrate, Codec
|
// Future tags to be defined for audio/video: Artist, Album, Title, Length, Bitrate, Codec
|
||||||
|
|||||||
14
Test_test.go
14
Test_test.go
@@ -95,11 +95,11 @@ func TestBlockEncoding(t *testing.T) {
|
|||||||
|
|
||||||
file1 := BlockRecordFile{Hash: hashData([]byte("Test data")), Type: TypeText, Format: FormatText, Size: 9, ID: uuid.New()}
|
file1 := BlockRecordFile{Hash: hashData([]byte("Test data")), Type: TypeText, Format: FormatText, Size: 9, ID: uuid.New()}
|
||||||
file1.TagsDecoded = append(file1.TagsDecoded, FileTagName{Name: "Filename 1.txt"})
|
file1.TagsDecoded = append(file1.TagsDecoded, FileTagName{Name: "Filename 1.txt"})
|
||||||
file1.TagsDecoded = append(file1.TagsDecoded, FileTagDirectory{Directory: "documents\\sub folder"})
|
file1.TagsDecoded = append(file1.TagsDecoded, FileTagFolder{Name: "documents\\sub folder"})
|
||||||
|
|
||||||
file2 := BlockRecordFile{Hash: hashData([]byte("Test data 2")), Type: TypeText, Format: FormatText, Size: 9, ID: uuid.New()}
|
file2 := BlockRecordFile{Hash: hashData([]byte("Test data 2")), Type: TypeText, Format: FormatText, Size: 9, ID: uuid.New()}
|
||||||
file2.TagsDecoded = append(file2.TagsDecoded, FileTagName{Name: "Filename 2.txt"})
|
file2.TagsDecoded = append(file2.TagsDecoded, FileTagName{Name: "Filename 2.txt"})
|
||||||
file2.TagsDecoded = append(file2.TagsDecoded, FileTagDirectory{Directory: "documents\\sub folder"})
|
file2.TagsDecoded = append(file2.TagsDecoded, FileTagFolder{Name: "documents\\sub folder"})
|
||||||
|
|
||||||
encodedFiles, _ := encodeBlockRecordFiles([]BlockRecordFile{file1, file2})
|
encodedFiles, _ := encodeBlockRecordFiles([]BlockRecordFile{file1, file2})
|
||||||
|
|
||||||
@@ -140,8 +140,8 @@ func TestBlockEncoding(t *testing.T) {
|
|||||||
switch v := decodedT.(type) {
|
switch v := decodedT.(type) {
|
||||||
case FileTagName:
|
case FileTagName:
|
||||||
fmt.Printf(" Name %s\n", v.Name)
|
fmt.Printf(" Name %s\n", v.Name)
|
||||||
case FileTagDirectory:
|
case FileTagFolder:
|
||||||
fmt.Printf(" Directory %s\n", v.Directory)
|
fmt.Printf(" Folder %s\n", v.Name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -164,7 +164,7 @@ func TestBlockchainAdd(t *testing.T) {
|
|||||||
|
|
||||||
file1 := BlockRecordFile{Hash: hashData([]byte("Test data")), Type: TypeText, Format: FormatText, Size: 9, ID: uuid.New()}
|
file1 := BlockRecordFile{Hash: hashData([]byte("Test data")), Type: TypeText, Format: FormatText, Size: 9, ID: uuid.New()}
|
||||||
file1.TagsDecoded = append(file1.TagsDecoded, FileTagName{Name: "Filename 1.txt"})
|
file1.TagsDecoded = append(file1.TagsDecoded, FileTagName{Name: "Filename 1.txt"})
|
||||||
file1.TagsDecoded = append(file1.TagsDecoded, FileTagDirectory{Directory: "documents\\sub folder"})
|
file1.TagsDecoded = append(file1.TagsDecoded, FileTagFolder{Name: "documents\\sub folder"})
|
||||||
|
|
||||||
newHeight, status := UserBlockchainAddFiles([]BlockRecordFile{file1})
|
newHeight, status := UserBlockchainAddFiles([]BlockRecordFile{file1})
|
||||||
|
|
||||||
@@ -223,8 +223,8 @@ func TestBlockchainRead(t *testing.T) {
|
|||||||
switch v := decodedT.(type) {
|
switch v := decodedT.(type) {
|
||||||
case FileTagName:
|
case FileTagName:
|
||||||
fmt.Printf(" Name %s\n", v.Name)
|
fmt.Printf(" Name %s\n", v.Name)
|
||||||
case FileTagDirectory:
|
case FileTagFolder:
|
||||||
fmt.Printf(" Directory %s\n", v.Directory)
|
fmt.Printf(" Folder %s\n", v.Name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user