@@ -59,6 +59,19 @@ vi.mock("expo-file-system", () => ({
5959 return files . get ( this . uri ) ?. mimeType ?? "" ;
6060 }
6161
62+ get size ( ) : number | null {
63+ const entry = files . get ( this . uri ) ;
64+ return entry && ! entry . deleted
65+ ? Math . floor ( ( entry . base64 . replace ( / = + $ / , "" ) . length * 3 ) / 4 )
66+ : null ;
67+ }
68+
69+ async copy ( destination : { readonly uri : string } ) : Promise < void > {
70+ const entry = files . get ( this . uri ) ;
71+ if ( ! entry ) throw new Error ( "missing file" ) ;
72+ files . set ( destination . uri , { ...entry } ) ;
73+ }
74+
6275 async base64 ( ) : Promise < string > {
6376 const entry = files . get ( this . uri ) ;
6477 if ( ! entry || entry . deleted ) {
@@ -98,14 +111,15 @@ vi.mock("expo-file-system", () => ({
98111
99112 create ( ) : void { }
100113 } ,
114+ FileMode : { ReadOnly : "r" , WriteOnly : "w" } ,
101115 Paths : { document : "file:///documents" } ,
102116} ) ) ;
103117
104118vi . mock ( "./uuid" , ( ) => ( {
105119 uuidv4 : ( ) => "attachment-id" ,
106120} ) ) ;
107121
108- import { convertPastedImagesToAttachments } from "./composerImages" ;
122+ import { convertPastedImagesToAttachments , persistComposerAttachmentFile } from "./composerImages" ;
109123
110124describe ( "native pasted image cleanup" , ( ) => {
111125 beforeEach ( ( ) => {
@@ -204,6 +218,22 @@ describe("native pasted image cleanup", () => {
204218 } ) ;
205219} ) ;
206220
221+ describe ( "persistComposerAttachmentFile" , ( ) => {
222+ beforeEach ( ( ) => {
223+ files . clear ( ) ;
224+ } ) ;
225+
226+ it ( "stores picked files under a name Android's java.net.URI accepts" , async ( ) => {
227+ const source = "file:///cache/DocumentPicker/Report [draft].pdf" ;
228+ files . set ( source , { base64 : "JVBERg==" , deleted : false } ) ;
229+
230+ const fileUri = await persistComposerAttachmentFile ( source , "Report [draft].pdf" ) ;
231+
232+ // expo-file-system encodes spaces and `%` but leaves `[`, `]`, `|` and `^` raw.
233+ expect ( fileUri . split ( "/" ) . at ( - 1 ) ) . toMatch ( / ^ [ \w \- . ! ~ * ' ( ) ; : @ & = + $ , % ] + \. p d f $ / ) ;
234+ } ) ;
235+ } ) ;
236+
207237describe ( "composerStripAttachments" , ( ) => {
208238 const image = {
209239 id : "img-1" ,
0 commit comments