packages feed

hslua-module-zip 1.0.0 → 1.1.0

raw patch · 6 files changed

+77/−57 lines, 6 filesdep +hslua-typingdep ~basedep ~hslua-coredep ~hslua-marshallingPVP ok

version bump matches the API change (PVP)

Dependencies added: hslua-typing

Dependency ranges changed: base, hslua-core, hslua-marshalling, hslua-packaging, tasty-lua

API changes (from Hackage documentation)

- HsLua.Module.Zip: mkArchive :: LuaError e => DocumentedFunction e
+ HsLua.Module.Zip: mkArchive :: forall e. LuaError e => DocumentedFunction e
- HsLua.Module.Zip: typeArchive :: LuaError e => DocumentedType e Archive
+ HsLua.Module.Zip: typeArchive :: forall e. LuaError e => DocumentedType e Archive
- HsLua.Module.Zip: typeEntry :: LuaError e => DocumentedType e Entry
+ HsLua.Module.Zip: typeEntry :: forall e. LuaError e => DocumentedType e Entry

Files

CHANGELOG.md view
@@ -4,7 +4,7 @@  ## hslua-module-zip-1.0.0 -Release pending.+Released 2023-03-13.  -   Initially created. 
LICENSE view
@@ -1,6 +1,6 @@ MIT License -Copyright © 2020-2022 Albert Krewinkel+Copyright © 2020-2023 Albert Krewinkel  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal
hslua-module-zip.cabal view
@@ -1,6 +1,6 @@ cabal-version:       2.2 name:                hslua-module-zip-version:             1.0.0+version:             1.1.0 synopsis:            Lua module to work with file zips. description:         Module with function for creating, modifying, and                      extracting files from zip archives.@@ -9,21 +9,20 @@ license:             MIT license-file:        LICENSE author:              Albert Krewinkel-maintainer:          Albert Krewinkel <albert@zeitkraut.de>-copyright:           © 2020-2022 Albert Krewinkel+maintainer:          Albert Krewinkel <tarleb@hslua.org>+copyright:           © 2020-2023 Albert Krewinkel category:            Foreign build-type:          Simple extra-doc-files:     README.md                      CHANGELOG.md extra-source-files:  test/test-zip.lua-tested-with:         GHC == 8.0.2-                   , GHC == 8.2.2-                   , GHC == 8.4.4+tested-with:         GHC == 8.4.4                    , GHC == 8.6.5                    , GHC == 8.8.4                    , GHC == 8.10.7                    , GHC == 9.0.2-                   , GHC == 9.2.3+                   , GHC == 9.2.5+                   , GHC == 9.4.4  source-repository head   type:                git@@ -31,13 +30,14 @@   subdir:              hslua-module-zip  common common-options-  build-depends:       base              >= 4.9.1  && < 5+  build-depends:       base              >= 4.11   && < 5                      , bytestring                      , filepath          >= 1.4    && < 1.5-                     , hslua-core        >= 2.1    && < 2.3+                     , hslua-core        >= 2.3    && < 2.4                      , hslua-list        >= 1.1    && < 1.2-                     , hslua-marshalling >= 2.1    && < 2.3-                     , hslua-packaging   >= 2.1    && < 2.3+                     , hslua-marshalling >= 2.3    && < 2.4+                     , hslua-packaging   >= 2.3    && < 2.4+                     , hslua-typing      >= 0.1    && < 0.2                      , text              >= 1.2    && < 2.1                      , time              >= 1.5    && < 1.14                      , zip-archive       >= 0.4    && < 0.5@@ -73,7 +73,7 @@                      , hslua-module-system                      , tasty                      , tasty-hunit-                     , tasty-lua         >= 1.0    && < 1.1+                     , tasty-lua         >= 1.0    && < 1.2                      , text   ghc-options:         -threaded                        -rtsopts
src/HsLua/Module/Zip.hs view
@@ -5,9 +5,9 @@ {-# LANGUAGE TypeApplications    #-} {-| Module      : HsLua.Module.Zip-Copyright   : © 2022 Albert Krewinkel+Copyright   : © 2022-2023 Albert Krewinkel License     : MIT-Maintainer  : Albert Krewinkel <albert+hslua@zeitkraut.de>+Maintainer  : Albert Krewinkel <tarleb@hslua.org>  Lua module to work with file zips. -}@@ -37,10 +37,8 @@ import Control.Applicative (optional) import Control.Monad ((<$!>)) import Codec.Archive.Zip (Archive, Entry, ZipOption (..), emptyArchive)+import Data.Functor ((<&>)) import Data.Maybe (catMaybes, fromMaybe)-#if !MIN_VERSION_base(4,11,0)-import Data.Semigroup (Semigroup(..))  -- includes (<>)-#endif import Data.Time.Clock.POSIX (getPOSIXTime) import Data.Version (Version, makeVersion) import HsLua.Core@@ -54,24 +52,34 @@   , pushLazyByteString, pushList, pushIntegral, pushString   , retrieving, typeMismatchMessage ) import HsLua.Packaging+import HsLua.Typing  import qualified Codec.Archive.Zip as Zip import qualified Data.Text as T -#if MIN_VERSION_base(4,11,0)-import Data.Functor ((<&>))-#else-(<&>) :: Functor f => f a -> (a -> b) -> f b-(<&>) = flip fmap-#endif  -- | The @zip@ module specification. documentedModule :: forall e. LuaError e => Module e documentedModule = Module   { moduleName = "zip"-  , moduleDescription = T.unwords-    [ "Function for creating, modifying, and extracting files from zip"-    , "archives."+  , moduleDescription = T.unlines+    [ "Functions to create, modify, and extract files from zip archives."+    , ""+    , "The module can be called as a function, in which case it behaves"+    , "like the `zip` function described below."+    , ""+    , "Zip options are optional; when defined, they must be a table with"+    , "any of the following keys:"+    , ""+    , "  - `recursive`: recurse directories when set to `true`;"+    , "  - `verbose`: print info messages to stdout;"+    , "  - `destination`: the value specifies the directory in which to"+    , "    extract;"+    , "  - `location`: value is used as path name, defining where files"+    , "    are placed."+    , "  - `preserve_symlinks`: Boolean value, controlling whether"+    , "    symbolic links are preserved as such. This option is ignored"+    , "    on Windows."     ]   , moduleFields = fields   , moduleFunctions = functions@@ -86,6 +94,10 @@               pure (NumResults 1))       =?> "new Archive"     ]+  , moduleTypeInitializers =+      [ initType typeArchive+      , initType typeEntry+      ]   }  -- | First published version of this library.@@ -167,10 +179,11 @@ --  -- | The Lua 'Archive' type-typeArchive :: LuaError e => DocumentedType e Archive-typeArchive = deftype "ZipArchive"+typeArchive :: forall e. LuaError e => DocumentedType e Archive+typeArchive = deftype "zip.Archive"   []-  [ property "entries" "files in this zip archive"+  [ property' "entries" (seqType (udTypeSpec @e typeEntry))+    "Files in this zip archive"     (pushEntries, Zip.zEntries)     (peekList peekEntryFuzzy, \ar entries -> ar { Zip.zEntries = entries })   , method extract@@ -178,7 +191,7 @@   ]  -- | Wrapper for 'Zip.toArchive'; converts a string into an Archive.-mkArchive :: LuaError e => DocumentedFunction e+mkArchive :: forall e. LuaError e => DocumentedFunction e mkArchive = defun "Archive"   ### (\case           Nothing                ->@@ -189,8 +202,9 @@             pure $ foldr Zip.addEntryToArchive emptyArchive entries)   <#> opt (parameter (choice [ fmap Left  . peekLazyByteString                              , fmap Right . peekList peekEntryFuzzy ])-           "string|{ZipEntry,...}" "contents"-           "binary archive data or list of entries")+           (stringType #|# seqType (udTypeSpec @e typeEntry))+           "bytestring_or_entries"+           "binary archive data or list of entries; defaults to an empty list")   =#> udresult typeArchive "new Archive"   #? T.unlines      [ "Reads an *Archive* structure from a raw zip archive or a list of"@@ -227,13 +241,15 @@ --  -- | The Lua type for 'Entry' objects.-typeEntry :: LuaError e => DocumentedType e Entry-typeEntry = deftype "ZipEntry"+typeEntry :: forall e. LuaError e => DocumentedType e Entry+typeEntry = deftype "zip.Entry"   []-  [ property "path" "relative path, using `/` as separator"+  [ property' "path" (udTypeSpec @e typeEntry)+    "Relative path, using `/` as separator"     (pushString, Zip.eRelativePath)     (peekString, \entry path -> entry { Zip.eRelativePath = path })-  , property "modtime" "modification time (seconds since unix epoch)"+  , property' "modtime" integerType+    "Modification time (seconds since unix epoch)"     (pushIntegral, Zip.eLastModified)     (peekIntegral, \entry modtime -> entry { Zip.eLastModified = modtime})   , method contents
test/test-hslua-module-zip.hs view
@@ -2,9 +2,9 @@ {-# LANGUAGE TypeApplications  #-} {-| Module      : Main-Copyright   : © 2021-2022 Albert Krewinkel+Copyright   : © 2021-2023 Albert Krewinkel License     : MIT-Maintainer  : Albert Krewinkel <albert+hslua@zeitkraut.de>+Maintainer  : Albert Krewinkel <tarleb@hslua.org> Stability   : stable Portability : Requires language extensions ForeignFunctionInterface,               OverloadedStrings.
test/test-zip.lua view
@@ -67,14 +67,18 @@     end),      test('module metamethod', function()-      local filename = 'greetings.txt'-      local fh = io.open(filename, 'w')-      fh:write('Hi Mom!\n')-      fh:close()-      assert.are_equal(-        zip.zip{filename}:bytestring(),-        zip{filename}:bytestring()-      )+      system.with_tmpdir('archive', function (tmpdir)+        system.with_wd(tmpdir, function ()+          local filename = 'greetings.txt'+          local fh = io.open(filename, 'w')+          fh:write('Hi Mom!\n')+          fh:close()+          assert.are_equal(+            zip.zip{filename}:bytestring(),+            zip{filename}:bytestring()+          )+        end)+      end)     end)   }, @@ -87,16 +91,17 @@             filename = filename,             contents = 'Hi Mom!\n',           }-          archive:extract{destination = 'foo'}-          assert.are_equal(system.ls()[1], 'foo')+          archive:extract()++          assert.are_equal(system.ls()[1], filename)           assert.are_equal(-            io.open('foo/' .. filename):read 'a',+            io.open(filename):read 'a',             'Hi Mom!\n'           )         end)       end)     end),-    test('archive with file', function ()+    test('to destination directory', function ()       system.with_tmpdir('archive', function (tmpdir)         system.with_wd(tmpdir, function ()           local filename = 'greetings.txt'@@ -104,16 +109,15 @@             filename = filename,             contents = 'Hi Mom!\n',           }-          archive:extract()--          assert.are_equal(system.ls()[1], filename)+          archive:extract{destination = 'foo'}+          assert.are_equal(system.ls()[1], 'foo')           assert.are_equal(-            io.open(filename):read 'a',+            io.open('foo/' .. filename):read 'a',             'Hi Mom!\n'           )         end)       end)-    end)+    end),   },    group 'entries' {