/// <summary> /// Sets the size (in bytes) of this file. Because /// <see cref="Write(long, MemoryStream)"/> to the file will grow /// it automatically if needed, this method is mainly usefull for truncating /// a file. /// </summary> /// <param name="length">the new length of the file in bytes</param> /// <exception cref="ReadOnlyException">ReadOnlyException if this file is read-only</exception> /// <exception cref="IOException">IOException on error updating the file size</exception> public void SetLength(long length) { CheckWritable(); if (GetLength() == length) { return; } UpdateTimeStamps(true); chain.SetSize(length); entry.SetStartCluster(chain.GetStartCluster()); entry.SetLength(length); }
internal override void ChangeSize(int entryCount) { if (entryCount == 0) { throw new Exception(); } var size = entryCount * FatDirectoryEntry.SIZE; if (size > MAX_SIZE) { throw new DirectoryFullException( "directory would grow beyond " + MAX_SIZE + " bytes", GetCapacity(), entryCount); } SizeChanged(Chain.SetSize(Math.Max(size, Chain.GetClusterSize()))); }