@@ -19,19 +19,19 @@ function Set-OpenPackage
1919 [Parameter (Mandatory , ValueFromPipelineByPropertyName )]
2020 [Alias (' Url' , ' Href' , ' PartUri' , ' PartUrl' , ' LocalPath' )]
2121 [uri ]
22- $Uri ,
23-
24- # The content type. By default, `text/plain`
25- [Parameter (ValueFromPipelineByPropertyName )]
26- [string ]
27- $ContentType = ' text/plain' ,
22+ $Uri ,
2823
2924 # The content to set.
3025 [Parameter (ValueFromPipelineByPropertyName )]
3126 [Alias (' Buffer' , ' Text' )]
3227 [PSObject ]
3328 $Content ,
3429
30+ # The content type. By default, `text/plain`
31+ [Parameter (ValueFromPipelineByPropertyName )]
32+ [string ]
33+ $ContentType ,
34+
3535 # The serialization depth.
3636 [Parameter (ValueFromPipelineByPropertyName )]
3737 [ValidateRange (1 , 100 )]
@@ -57,6 +57,13 @@ function Set-OpenPackage
5757 [PSObject ]
5858 $InputObject ,
5959
60+ # A content type map.
61+ # This maps extensions and URIs to a content type.
62+ [Collections.IDictionary ]
63+ $TypeMap = $ (
64+ ([PSCustomObject ]@ {PSTypeName = ' OpenPackage.ContentTypeMap' }).TypeMap
65+ ),
66+
6067 # Sets a part, even if it already exists.
6168 [switch ]
6269 $Force
@@ -85,6 +92,14 @@ function Set-OpenPackage
8592
8693 $InputObject.GetPart ($uri )
8794 } else {
95+ if (-not $PSBoundParameters [' ContentType' ]) {
96+ $extension = @ ($uri -split ' \.' -ne ' ' )[-1 ]
97+ if ($typeMap.TypeMap.Contains ($extension )) {
98+ $contentType = $typeMap.TypeMap [$extension ]
99+ } else {
100+ $contentType = ' text/plain'
101+ }
102+ }
88103 $InputObject.CreatePart ($uri , $ContentType )
89104 }
90105
0 commit comments