Skip to content
Permalink
Browse files

A bit of File{.,#}{size,truncate}

  • Loading branch information
alex committed Jun 22, 2013
1 parent c831386 commit 3405503bd90c634ae94408e46208542666a34c99
Showing with 14 additions and 17 deletions.
  1. +14 −0 lib-topaz/file.rb
  2. +0 −9 spec/tags/core/file/size_tags.txt
  3. +0 −8 spec/tags/core/file/truncate_tags.txt
@@ -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
@@ -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
@@ -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.
You can’t perform that action at this time.