Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
A bit of File{.,#}{size,truncate}
  • Loading branch information
alex committed Jun 22, 2013
1 parent c831386 commit 3405503
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 17 deletions.
14 changes: 14 additions & 0 deletions lib-topaz/file.rb
Expand Up @@ -9,6 +9,20 @@ def self.open(filename, mode="r", perm=nil, opt=nil, &block)
end
end

def self.truncate(filename, length)
File.open(filename) do |f|
f.truncate(length)
end
end

def self.size(filename)
return File.stat(filename).size
end

def size
return self.stat.size
end

def zero?
self.size == 0
end
Expand Down
9 changes: 0 additions & 9 deletions spec/tags/core/file/size_tags.txt
@@ -1,17 +1,8 @@
fails:File.size? calls #to_io to convert the argument to an IO
fails:File.size? accepts a File argument
fails:File.size returns the size of the file if it exists and is not empty
fails:File.size accepts a String-like (to_str) parameter
fails:File.size accepts an object that has a #to_path method
fails:File.size calls #to_io to convert the argument to an IO
fails:File.size raises an error if file_name doesn't exist
fails:File.size returns 0 if the file is empty
fails:File.size accepts a File argument
fails:File#size is an instance method
fails:File#size returns the file's size as a Fixnum
fails:File#size returns the file's size in bytes
fails:File#size returns the cached size of the file if subsequently deleted
fails:File#size returns the file's current size even if modified
fails:File#size raises an IOError on a closed file
fails:File#size follows symlinks if necessary
fails:File#size for an empty file returns 0
8 changes: 0 additions & 8 deletions spec/tags/core/file/truncate_tags.txt
Expand Up @@ -3,15 +3,7 @@ fails:File.truncate truncate a file size to 0
fails:File.truncate truncate a file size to 5
fails:File.truncate truncates to a larger file size than the original file
fails:File.truncate truncates to the same size as the original file
fails:File.truncate raises an Errno::ENOENT if the file does not exist
fails:File.truncate raises an ArgumentError if not passed two arguments
fails:File.truncate raises an Errno::EINVAL if the length argument is not valid
fails:File.truncate raises a TypeError if not passed a String type for the first argument
fails:File.truncate raises a TypeError if not passed an Integer type for the second argument
fails:File.truncate accepts an object that has a #to_path method
fails:File#truncate truncates a file
fails:File#truncate truncates a file size to 0
fails:File#truncate truncates a file size to 5
fails:File#truncate truncates a file to a larger size than the original file
fails:File#truncate truncates a file to the same size as the original file
fails:File#truncate raises an IOError if file is not opened for writing

0 comments on commit 3405503

Please sign in to comment.