diff --git a/README.md b/README.md index ba2ee2b..c6e9f69 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ Link in this list point to their `love.filesystem` counterparts. All functions a Functions that are not available in `love.filesystem`: * `nativefs.getDirectoryItemsInfo(path)` -Returns a list of items in a directory that contains not only the names, but also the information returned by `getInfo` for each item. The return value is a list of files, in which each entry is a table as returned by [getInfo](https://love2d.org/wiki/love.filesystem.getInfo), with an additional `name` field for each file. +Returns a list of items in a directory that contains not only the names, but also the information returned by `getInfo` for each item. The return value is a list of files and directories, in which each entry is a table as returned by [getInfo](https://love2d.org/wiki/love.filesystem.getInfo), with an additional `name` field for each entry. * `nativefs.getDriveList()` Returns a table of all populated drive letters on Windows (`{ 'C:/', 'D:/', ...}`). On systems that don't use drive letters, a table with the single entry `/` is returned. @@ -58,6 +58,8 @@ Changes the working directory. * [File:seek](https://love2d.org/wiki/\(File\):seek) * [File:tell](https://love2d.org/wiki/\(File\):tell) * [File:flush](https://love2d.org/wiki/\(File\):flush) +* [File:type](https://love2d.org/wiki/Object:type) +* [File:typeOf](https://love2d.org/wiki/Object:typeOf) * [File:release](https://love2d.org/wiki/Object:release) Function names in this list are links to their LÖVE `File` counterparts. `File` is designed to work the same way as LÖVE's `File` class. diff --git a/nativefs.lua b/nativefs.lua index 497103e..0bf64b4 100644 --- a/nativefs.lua +++ b/nativefs.lua @@ -41,17 +41,13 @@ function File:setBuffer(mode, size) return false, "Invalid buffer mode " .. mode .. " (expected 'none', 'full', or 'line')" end - if mode == 'line' or mode == 'full' then - size = math.max(2, size or 2) -- Windows requires buffer to be at least 2 bytes - else + if mode == 'none' then size = math.max(0, size or 0) - end - if self._mode == 'c' then - self._bufferMode, self._bufferSize = mode, size - return true + else + size = math.max(2, size or 2) -- Windows requires buffer to be at least 2 bytes end - local success = C.setvbuf(self._handle, nil, bufferMode, size) == 0 + local success = self._mode == 'c' or C.setvbuf(self._handle, nil, bufferMode, size) == 0 if success then self._bufferMode, self._bufferSize = mode, size return true @@ -75,7 +71,7 @@ function File:getSize() else self:seek(pos) end - return size; + return size end function File:read(containerOrBytes, bytes) @@ -181,6 +177,10 @@ function File:release() self._handle = nil end +function File:type() return 'File' end + +function File:typeOf(t) return t == 'File' end + File.__index = File ----------------------------------------------------------------------------- diff --git a/test/main.lua b/test/main.lua index 95229a7..23c727b 100644 --- a/test/main.lua +++ b/test/main.lua @@ -29,6 +29,10 @@ local testFile2, testSize2 = 'data/𠆢ßЩ.txt', 450 function test_fs_newFile() local file = fs.newFile('test.file') notEquals(file, nil) + equals(file:type(), 'File') + equals(file:typeOf('File'), true) + equals(file:getMode(), 'c') + equals(file:isEOF(), true) equals(file:getFilename(), 'test.file') end