Skip to content

Commit

Permalink
$mol_file improve copy api
Browse files Browse the repository at this point in the history
  • Loading branch information
zerkalica committed Oct 21, 2024
1 parent b09523c commit 65bc5ee
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 40 deletions.
6 changes: 3 additions & 3 deletions build/build.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1413,10 +1413,10 @@ namespace $ {

const pushFile = (file:$mol_file) => {
const start = Date.now()
const target = pack.resolve( `-/${ file.relate( root ) }` )
// target.buffer( file.buffer() )
target.copy_src(file.path())

const target = file.clone(pack.resolve( `-/${ file.relate( root ) }` ).path())
target.stat()

targets.push( target )
this.logBundle( target , Date.now() - start )
}
Expand Down
9 changes: 1 addition & 8 deletions file/file.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,6 @@ namespace $ {
}

export class $mol_file_node extends $mol_file {

@ $mol_mem_key
static absolute( path : string ) {
return this.make({
path : $mol_const( path )
})
}

static relative( path : string ) {
return this.absolute( $node.path.resolve( this.base, path ).replace( /\\/g , '/' ) )
Expand Down Expand Up @@ -209,7 +202,7 @@ namespace $ {
override relate( base = ( this.constructor as typeof $mol_file ).relative( '.' )) {
return $node.path.relative( base.path() , this.path() ).replace( /\\/g , '/' )
}

override append( next : Uint8Array | string ) {
const path = this.path()
try {
Expand Down
43 changes: 30 additions & 13 deletions file/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ namespace $ {

// export class $mol_file_not_found extends Error {}

export abstract class $mol_file extends $mol_object {
export class $mol_file extends $mol_object {

@ $mol_mem_key
static absolute( path : string ): $mol_file {
throw new Error( 'Not implemented yet' )
static absolute( path : string ) {
return this.make({
path : $mol_const( path )
})
}

static relative( path : string ) : $mol_file {
Expand All @@ -33,7 +35,17 @@ namespace $ {
return this.resolve( '..' )
}

abstract stat(next? : $mol_file_stat | null, virt?: 'virt'): null | $mol_file_stat
@ $mol_mem_key
clone(path: string) {
return ( this.constructor as typeof $mol_file ).make({
path: $mol_const(path),
copy_src: () => this.path()
})
}

stat(next? : $mol_file_stat | null, virt?: 'virt'): null | $mol_file_stat {
return null
}

reset() { this.stat(null) }
reset_schedule() { return this.$.$mol_file.reset_schedule(this.path()) }
Expand Down Expand Up @@ -66,8 +78,8 @@ namespace $ {
return this.stat()?.mtime.getTime().toString( 36 ).toUpperCase() ?? ''
}

abstract ensure(): void
abstract drop(): void
ensure() {}
drop() {}

watcher(reset?: null) {
console.warn('$mol_file_web.watcher() not implemented')
Expand Down Expand Up @@ -110,7 +122,8 @@ namespace $ {
return match ? match[ 1 ].substring( 1 ) : ''
}

abstract buffer( next? : Uint8Array ): Uint8Array
@ $mol_mem
buffer( next? : Uint8Array ) { return next ?? new Uint8Array }

@ $mol_mem
copy_src(path?: string) {
Expand Down Expand Up @@ -150,13 +163,17 @@ namespace $ {
}
}

abstract sub(): $mol_file[]
sub() { return [] as $mol_file[] }

abstract resolve(path: string): $mol_file
resolve(path: string): $mol_file {
throw new Error('implement')
}

abstract relate( base?: $mol_file ): string

abstract append( next : Uint8Array | string ): void
relate( base?: $mol_file ): string {
throw new Error('implement')
}

append( next : Uint8Array | string ) {}

find(
include? : RegExp ,
Expand Down
26 changes: 10 additions & 16 deletions file/file.web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,7 @@ namespace $ {

export class $mol_file_web extends $mol_file {

@ $mol_mem_key
static absolute( path : string ) {
return this.make({
path : $mol_const( path )
})
}

static relative( path : string ) {
static override relative( path : string ) {
return this.absolute( new URL( path , this.base ).toString() )
}

Expand All @@ -18,7 +11,7 @@ namespace $ {
: ''

@ $mol_mem
buffer( next? : Uint8Array ) {
override buffer( next? : Uint8Array ) {
if (next !== undefined) throw new Error(`Saving content not supported: ${this.path}`)

const response = $mol_fetch.response(this.path())
Expand All @@ -29,7 +22,8 @@ namespace $ {
}

@ $mol_mem
stat( next? : $mol_file_stat, virt?: 'virt' ) {
override stat( next? : $mol_file_stat, virt?: 'virt' ) {
this.copy_sync()
let stat = next
if (next === undefined) {
const content = this.text()
Expand All @@ -49,7 +43,7 @@ namespace $ {
return stat!
}

resolve( path : string ) {
override resolve( path : string ) {
let res = this.path() + '/' + path

while( true ) {
Expand All @@ -61,24 +55,24 @@ namespace $ {
return ( this.constructor as typeof $mol_file_web ).absolute( res )
}

ensure() {
override ensure() {
throw new Error('$mol_file_web.ensure() not implemented')
}

drop() {
override drop() {
throw new Error('$mol_file_web.drop() not implemented')
}

@ $mol_mem
sub() : $mol_file[] {
override sub() : $mol_file[] {
throw new Error('$mol_file_web.sub() not implemented')
}

relate( base = ( this.constructor as typeof $mol_file ).relative( '.' )): string {
override relate( base = ( this.constructor as typeof $mol_file ).relative( '.' )): string {
throw new Error('$mol_file_web.relate() not implemented')
}

append( next : Uint8Array | string ) {
override append( next : Uint8Array | string ) {
throw new Error('$mol_file_web.append() not implemented')
}
}
Expand Down

0 comments on commit 65bc5ee

Please sign in to comment.