Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sequtils
- type
- Header* = object
- name*: array[0..100, char]
- mode*: array[0..8, char]
- uid*: array[0..8, char]
- gid*: array[0..8, char]
- size*: array[0..12, char]
- mktime*: array[0..12, char]
- chksum*: array[0..8, char]
- typeflag*: char
- linkname*: array[0..100, char]
- magic*: array[0..6, char]
- version*: array[0..2, char]
- uname*: array[0..32, char]
- gname*: array[0..32, char]
- devmajor*: array[0..8, char]
- devminor*: array[0..8, char]
- prefix*: array[0..155, char]
- gnu_longname*: ref char
- gnu_longlink*: ref char
- ArchiveFile* = object
- header*: Header
- pos*: uint64
- size*: uint64
- Archive* = object
- file: File
- files*: seq[ArchiveFile]
- position: uint64
- ArchiveException = object of Exception
- proc newTarArchive*(f: File): Archive =
- result = Archive(
- file: f
- )
- proc newHeader*(): Header =
- result = Header()
- proc parseBufferToHeader*(buffer: var array[0..512, char]): Header =
- result = newHeader()
- #result.name = buffer[0..100]
- result.name = buffer[0..100]
- proc readArchiveFile*(a: Archive): ArchiveFile =
- var buffer: array[0..512, char]
- let readCount: int = readChars(a.file, buffer, a.position, 512)
- if readCount != 512:
- raise newException(ArchiveException, "Could not read 512 bytes")
- let header = buffer.parseBufferToHeader()
- result = ArchiveFile(
- header: header)
Advertisement
Add Comment
Please, Sign In to add comment