Browse Source

Added DataStream() to TWriteArchive, returning a writeable TStream.

Brucey 2 years ago
parent
commit
a971c7348a
1 changed files with 50 additions and 2 deletions
  1. 50 2
      core.mod/core.bmx

+ 50 - 2
core.mod/core.bmx

@@ -35,6 +35,7 @@ ModuleInfo "Copyright: Wrapper - 2013-2022 Bruce A Henderson"
 
 ModuleInfo "History: 1.07"
 ModuleInfo "History: Update to libarchive 3.6.2.2d32907."
+ModuleInfo "History: Added DataStream() to TWriteArchive, returning a writeable TStream."
 ModuleInfo "History: 1.06"
 ModuleInfo "History: Update to libarchive 3.5.2.b967588."
 ModuleInfo "History: 1.05"
@@ -307,7 +308,7 @@ Public
 	about: This can be used by any #TStream supported functionality.
 	End Rem
 	Method DataStream:TStream()
-		Return New TArchiveStream(Self)
+		Return New TArchiveInputStream(Self)
 	End Method
 
 	Rem
@@ -350,7 +351,7 @@ End Type
 Rem
 bbdoc: Data from a TReadArchive entry as a stream.
 End Rem
-Type TArchiveStream Extends TStream
+Type TArchiveInputStream Extends TStream
 
 	Field archive:TArchive
 	
@@ -389,6 +390,33 @@ Type TArchiveStream Extends TStream
 
 End Type
 
+Type TArchiveOutputStream Extends TStream
+
+	Field archive:TWriteArchive
+	
+	Field _eof:Int
+	
+	Method New(archive:TWriteArchive)
+		Self.archive = archive
+	End Method
+
+	Method Write:Long( buf:Byte Ptr,count:Long )
+		Return archive.Data(buf, Size_T(count))
+	End Method
+
+	Method WriteBytes:Long( buf:Byte Ptr,count:Long )
+		Local t:Long=count
+		While count>0
+			Local n:Long=Write( buf,count )
+			If Not n Exit
+			count:-n
+			buf:+n
+		Wend
+		Return t
+	End Method
+
+End Type
+
 Type TArchiveCallbackData
 
 	Field data:Byte[]
@@ -478,6 +506,17 @@ Type TWriteArchive Extends TArchive
 		archivePtr = bmx_libarchive_write_archive_new()
 	End Method
 
+	Rem
+	bbdoc: Creates a new instance of #TWriteArchive with the specified format and filters.
+	End Rem
+	Method New(format:EArchiveFormat, filters:EArchiveFilter[])
+		New()
+		SetFormat(format)
+		For Local filter:EArchiveFilter = Eachin filters
+			AddFilter(filter)
+		Next
+	End Method
+
 	Rem
 	bbdoc: Opens archive for writing to a file of the given @filename.
 	about: The file should be writeable.
@@ -631,6 +670,14 @@ Type TWriteArchive Extends TArchive
 		Return bmx_libarchive_archive_write_data(archivePtr, data, size)
 	End Method
 
+	Rem
+	bbdoc: Returns a writeable #TStream.
+	about: This can be used by any #TStream supported functionality.
+	End Rem
+	Method DataStream:TStream()
+		Return New TArchiveOutputStream(Self)
+	End Method
+
 	Rem
 	bbdoc: Sets a passphrase for the archive.
 	End Rem
@@ -758,6 +805,7 @@ Type TArchiveEntry
 	End Rem
 	Method New()
 		entryPtr = bmx_libarchive_archive_entry_new()
+		SetFileType(EArchiveFileType.File)
 	End Method
 
 	Rem