Chinaunix首页 | 论坛 | 博客
  • 博客访问: 188405
  • 博文数量: 106
  • 博客积分: 3810
  • 博客等级: 中校
  • 技术积分: 1007
  • 用 户 组: 普通用户
  • 注册时间: 2009-03-18 13:35
文章分类

全部博文(106)

文章存档

2014年(17)

2011年(5)

2010年(75)

2009年(9)

我的朋友

分类:

2010-04-26 17:28:54

Imports System

' 此类代表压缩文件中的某一个项目(也就是某一个档案的压缩数据)。

Public Class ZipEntry
    ' 私有字段。
    Private thisSize As Int32
    Private thisCompressedSize As Int32
    Private thisDosTime As Int32 ' 以 Int 来表示的时间。
    Private thisNameLength As Int16 ' 变动大小名称的长度。
    Private thisCrc() As Byte ' 16 个 CRC 字节的数组。
    Private thisName As String


    ' 使用指定的名称于压缩文件中建立一个项目。
    ' 所指定的名称可能会内含以 '/' 分隔的目录。
    Public Sub New(ByVal newName As String)
        If newName Is Nothing Then
            ' 错误的输入项目。
            Throw New System.ArgumentNullException()
        End If
        Me.ModifiedDateTime = System.DateTime.Now
        Me.Name = newName
        Me.thisSize = 0
        Me.thisCompressedSize = 0
        Me.thisCrc = New Byte(15) {}

    End Sub 'New

    Public Property DosTime() As Int32
        Get
            Return thisDosTime
        End Get
        Set(ByVal value As Int32)
            Me.thisDosTime = value
        End Set
    End Property


    Public Property NameLength() As Int16
        Get
            Return thisNameLength
        End Get
        Set(ByVal value As Int16)
            ' 检查此值是否大于 16 个字节。
            If CType(value, Int16) > &HFFFF Then
                Throw New ArgumentOutOfRangeException()
            End If
            Me.thisNameLength = value
        End Set
    End Property

    ' 取得或设定项目最后一次的修改时间。
    Public Property ModifiedDateTime() As DateTime
        Get
            Dim sec As Integer = 2 * (thisDosTime And &H1F)
            Dim min As Integer = (thisDosTime >> 5) And &H3F
            Dim hrs As Integer = (thisDosTime >> 11) And &H1F
            Dim day As Integer = (thisDosTime >> 16) And &H1F
            Dim mon As Integer = (thisDosTime >> 21) And &HF
            Dim year As Integer = ((thisDosTime >> 25) And &H7F) + 1980 ' since 1900
            Return New System.DateTime(year, mon, day, hrs, min, sec)
        End Get
        Set(ByVal value As DateTime)
            DosTime = ((CType(value.Year, Int32) - 1980 And &H7F) << 25) _
                Or (CType(value.Month, Int32) << 21) Or _
                (CType(value.Day, Int32) << 16) Or (CType(value.Hour, Int32) << 11) _
                Or (CType(value.Minute, Int32) << 5) Or (CType(value.Second, Int32) >> 1)
        End Set
    End Property

    ' 传回项目的名称。 项目中的路径部分固定会以斜线 '/' 来分隔。
    Public Property Name() As String
        Get
            Return thisName
        End Get
        Set(ByVal value As String)
            ' 检查此值是否大于 16 个字节或是为 null。
            If Value Is Nothing OrElse Value.Length > &HFFFFL Then
                Throw New ArgumentOutOfRangeException()
            End If
            If Value.Length <> 0 Then
                thisName = Value
                thisNameLength = CType(Value.Length, Int16)
            End If
        End Set
    End Property

    ' 取得或设定未压缩数据的大小。
    Public Property Size() As Int32
        Get
            Return thisSize
        End Get
        Set(ByVal value As Int32)
            ' 检查此值是否大于 32 个字节。
            If CType(value, Int32) > Int32.MaxValue Then
                Throw New ArgumentOutOfRangeException()
            End If
            thisSize = CType(value, Int32)
        End Set
    End Property

    ' 取得或设定压缩数据的大小。
    Public Property CompressedSize() As Int32
        Get
            Return thisCompressedSize
        End Get
        Set(ByVal value As Int32)
            ' 检查此值是否大于 32 个字节。
            If CType(value, Int32) > Int32.MaxValue Then
                Throw New ArgumentOutOfRangeException()
            End If
            Me.thisCompressedSize = CType(value, Int32)
        End Set
    End Property

    ' 取得或设定压缩数据的 crc。
    Public Function GetCrc() As Byte()
        Return thisCrc
    End Function 'GetCrc

    Public Sub SetCrc(ByVal value() As Byte)
        ' 检查值数组的长度是否大于 16 。
        If value.Length <> thisCrc.Length Then
            Throw New ArgumentOutOfRangeException()
        End If
        thisCrc = value
    End Sub 'SetCrc
End Class 'ZipEntry


阅读(227) | 评论(0) | 转发(0) |
0

上一篇:.Net经典压缩类 1

下一篇:.Net经典压缩类3

给主人留下些什么吧!~~