1
- import {
2
- AWSSignerV4 ,
3
- decodeXMLEntities ,
4
- parseXML ,
5
- pooledMap ,
6
- } from "../deps.ts" ;
1
+ import { AWSSignerV4 , parseXML , pooledMap } from "../deps.ts" ;
7
2
import type { S3Config } from "./client.ts" ;
8
3
import type {
9
4
CommonPrefix ,
@@ -27,6 +22,8 @@ import { S3Error } from "./error.ts";
27
22
import type { Signer } from "../deps.ts" ;
28
23
import { doRequest , encodeURIS3 } from "./request.ts" ;
29
24
import type { Params } from "./request.ts" ;
25
+ import type { Document } from "./xml.ts" ;
26
+ import { extractContent , extractField , extractRoot } from "./xml.ts" ;
30
27
31
28
export interface S3BucketConfig extends S3Config {
32
29
bucket : string ;
@@ -330,9 +327,7 @@ export class S3Bucket {
330
327
}
331
328
332
329
const parsed = {
333
- isTruncated : extractContent ( root , "IsTruncated" ) === "true"
334
- ? true
335
- : false ,
330
+ isTruncated : extractContent ( root , "IsTruncated" ) === "true" ,
336
331
contents : root . children
337
332
. filter ( ( node ) => node . name === "Contents" )
338
333
. map < S3Object > ( ( s3obj ) => {
@@ -625,40 +620,3 @@ export class S3Bucket {
625
620
return deleted ;
626
621
}
627
622
}
628
-
629
- interface Document {
630
- declaration : {
631
- attributes : Record < string , unknown > ;
632
- } ;
633
- root : Xml | undefined ;
634
- }
635
-
636
- interface Xml {
637
- name : string ;
638
- attributes : unknown ;
639
- children : Xml [ ] ;
640
- content ?: string ;
641
- }
642
-
643
- function extractRoot ( doc : Document , name : string ) : Xml {
644
- if ( ! doc . root || doc . root . name !== name ) {
645
- throw new S3Error (
646
- `Malformed XML document. Missing ${ name } field.` ,
647
- JSON . stringify ( doc , undefined , 2 ) ,
648
- ) ;
649
- }
650
- return doc . root ;
651
- }
652
-
653
- function extractField ( node : Xml , name : string ) : Xml | undefined {
654
- return node . children . find ( ( node ) => node . name === name ) ;
655
- }
656
-
657
- function extractContent ( node : Xml , name : string ) : string | undefined {
658
- const field = extractField ( node , name ) ;
659
- const content = field ?. content ;
660
- if ( content === undefined ) {
661
- return content ;
662
- }
663
- return decodeXMLEntities ( content ) ;
664
- }
0 commit comments