Class FileStorage
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final file_flags_tThis file is executable (sets the executable bit on posix like systems).static final file_flags_tThis file is hidden (sets the hidden attribute on windows).static final file_flags_tThis file is a pad file.static final file_flags_tThis file is a symlink. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a file to the file storage.voidaddFile(String path, long size, file_flags_t flags) Adds a file to the file storage.voidaddFile(String path, long size, file_flags_t flags, int mtime) Adds a file to the file storage.voidaddFile(String path, long size, file_flags_t flags, int mtime, String symlink) Adds a file to the file storage.booleanfileAbsolutePath(int index) Returns true if the file at the specified index has been renamed to have an absolute path, i.e.fileFlags(int index) Returns a bitmask of flags fromfile_flags_tthat apply to file atindex.intfileIndexAtOffset(long offset) Returns the index of the file at the given offset in the torrent.fileName(int index) Returns only the name of the file, whereasfilePath(int)returns the path (inside the torrent file) with the filename appended.longfileOffset(int index) returns the byte offset within the torrent file where this file starts.filePath(int index) Returns the full path to a file.returns the full path to a file.longfileSize(int index) returns the size of a file.hash(int index) Is a sha-1 hash of the file, or 0 if none was provided in the torrent file.booleanisValid()Returns true if the piece length has been initialized on the file_storage.mapBlock(int piece, long offset, int size) Returns a list ofFileSliceobjects representing the portions of files the specified piece index, byte offset and size range overlaps.mapFile(int file, long offset, int size) Returns aPeerRequestrepresenting the piece index, byte offset and size the specified file range overlaps.name()Get the name of this torrent.voidSet the name of this torrent.intnumFiles()Returns the number of files in the file_storage.intReturns the number of pieces in the torrent.voidnumPieces(int n) Set the number of pieces in the torrent.booleanpadFileAt(int index) returns true if the file at the given index is a pad-file.paths()intGet the size of each piece in this torrent.voidpieceLength(int l) Set the size of each piece in this torrent.intpieceSize(int index) Returns the piece size ofindex.voidrenameFile(int index, String newFilename) Renames the file atindextonewFilename.voidreserve(int numFiles) Allocates space fornumFilesin the internal file list.swig()ti()This methods returns the internal torrent info or null if it was constructed without one.longReturns the total number of bytes all the files in this torrent spans.
-
Field Details
-
FLAG_PAD_FILE
This file is a pad file. The creator of the torrent promises the file is entirely filled with zeroes and does not need to be downloaded. The purpose is just to align the next file to either a block or piece boundary. -
FLAG_HIDDEN
This file is hidden (sets the hidden attribute on windows). -
FLAG_EXECUTABLE
This file is executable (sets the executable bit on posix like systems). -
FLAG_SYMLINK
This file is a symlink. The symlink target is specified in a separate field
-
-
Constructor Details
-
FileStorage
- Parameters:
fs- the native object
-
-
Method Details
-
swig
- Returns:
- the native object
-
ti
This methods returns the internal torrent info or null if it was constructed without one.This also prevent premature garbage collection in case the storage was created from a torrent info.
- Returns:
- the pinned torrent info
-
isValid
public boolean isValid()Returns true if the piece length has been initialized on the file_storage. This is typically taken as a proxy of whether the file_storage as a whole is initialized or not.- Returns:
- true if valid
-
reserve
public void reserve(int numFiles) Allocates space fornumFilesin the internal file list. This can be used to avoid reallocating the internal file list when the number of files to be added is known up-front.- Parameters:
numFiles- the number of files
-
addFile
Adds a file to the file storage. Theflagsargument sets attributes on the file. The file attributes is an extension and may not work in all bittorrent clients.If more files than one are added, certain restrictions to their paths apply. In a multi-file file storage (torrent), all files must share the same root directory.
That is, the first path element of all files must be the same. This shared path element is also set to the name of the torrent. It can be changed by calling
name(String).The built in functions to traverse a directory to add files will make sure this requirement is fulfilled.
- Parameters:
path- the pathsize- the file sizeflags- the file flagsmtime- the timesymlink- the symlink
-
addFile
Adds a file to the file storage. Theflagsargument sets attributes on the file. The file attributes is an extension and may not work in all bittorrent clients.If more files than one are added, certain restrictions to their paths apply. In a multi-file file storage (torrent), all files must share the same root directory.
That is, the first path element of all files must be the same. This shared path element is also set to the name of the torrent. It can be changed by calling
name(String).The built in functions to traverse a directory to add files will make sure this requirement is fulfilled.
- Parameters:
path- the pathsize- the file sizeflags- the file flagsmtime- the time
-
addFile
Adds a file to the file storage. Theflagsargument sets attributes on the file. The file attributes is an extension and may not work in all bittorrent clients.If more files than one are added, certain restrictions to their paths apply. In a multi-file file storage (torrent), all files must share the same root directory.
That is, the first path element of all files must be the same. This shared path element is also set to the name of the torrent. It can be changed by calling
name(String).The built in functions to traverse a directory to add files will make sure this requirement is fulfilled.
- Parameters:
path- the pathsize- the file sizeflags- the file flags
-
addFile
Adds a file to the file storage.If more files than one are added, certain restrictions to their paths apply. In a multi-file file storage (torrent), all files must share the same root directory.
That is, the first path element of all files must be the same. This shared path element is also set to the name of the torrent. It can be changed by calling
name(String).The built in functions to traverse a directory to add files will make sure this requirement is fulfilled.
- Parameters:
p-size-
-
renameFile
Renames the file atindextonewFilename. Keep in mind that filenames are expected to be UTF-8 encoded.- Parameters:
index-newFilename-
-
mapBlock
Returns a list ofFileSliceobjects representing the portions of files the specified piece index, byte offset and size range overlaps.This is the inverse mapping of
mapFile(int, long, int).- Parameters:
piece-offset-size-- Returns:
-
mapFile
Returns aPeerRequestrepresenting the piece index, byte offset and size the specified file range overlaps. This is the inverse mapping ofmapBlock(int, long, int).Note that the
PeerRequestreturn type is meant to hold bittorrent block requests, which may not be larger than 16 kiB. Mapping a range larger than that may return an overflown integer.- Parameters:
file-offset-size-- Returns:
-
numFiles
public int numFiles()Returns the number of files in the file_storage.- Returns:
-
totalSize
public long totalSize()Returns the total number of bytes all the files in this torrent spans.- Returns:
-
numPieces
public int numPieces()Returns the number of pieces in the torrent.- Returns:
- the number of pieces in the torrent
-
numPieces
public void numPieces(int n) Set the number of pieces in the torrent.- Parameters:
n-
-
pieceLength
public int pieceLength()Get the size of each piece in this torrent. This size is typically an even power of 2. It doesn't have to be though. It should be divisible by 16kiB however.- Returns:
-
pieceLength
public void pieceLength(int l) Set the size of each piece in this torrent. This size is typically an even power of 2. It doesn't have to be though. It should be divisible by 16kiB however.- Parameters:
l-
-
pieceSize
public int pieceSize(int index) Returns the piece size ofindex. This will be the same aspieceLength(), except for the last piece, which may be shorter.- Parameters:
index-- Returns:
-
name
Get the name of this torrent. For multi-file torrents, this is also the name of the root directory all the files are stored in.- Returns:
-
name
Set the name of this torrent. For multi-file torrents, this is also the name of the root directory all the files are stored in.- Parameters:
name-
-
hash
Is a sha-1 hash of the file, or 0 if none was provided in the torrent file. This can potentially be used to join a bittorrent network with other file sharing networks.- Parameters:
index-- Returns:
-
filePath
-
filePath
Returns the full path to a file.- Parameters:
index- the file index- Returns:
- the full path
-
fileName
Returns only the name of the file, whereasfilePath(int)returns the path (inside the torrent file) with the filename appended.- Parameters:
index- the file index- Returns:
- the file name
-
fileSize
public long fileSize(int index) returns the size of a file.- Parameters:
index-- Returns:
-
padFileAt
public boolean padFileAt(int index) returns true if the file at the given index is a pad-file.- Parameters:
index-- Returns:
-
fileOffset
public long fileOffset(int index) returns the byte offset within the torrent file where this file starts. It can be used to map the file to a piece index (given the piece size).- Parameters:
index-- Returns:
-
paths
-
fileFlags
Returns a bitmask of flags fromfile_flags_tthat apply to file atindex.- Parameters:
index-- Returns:
- the flags
-
fileAbsolutePath
public boolean fileAbsolutePath(int index) Returns true if the file at the specified index has been renamed to have an absolute path, i.e. is not anchored in the save path of the torrent.- Parameters:
index-- Returns:
-
fileIndexAtOffset
public int fileIndexAtOffset(long offset) Returns the index of the file at the given offset in the torrent.- Parameters:
offset-- Returns:
-