Giter Site home page Giter Site logo

Wrong 'output' path about epg HOT 2 OPEN

ewwink avatar ewwink commented on May 27, 2024 1
Wrong 'output' path

from epg.

Comments (2)

demod-au avatar demod-au commented on May 27, 2024

thanks.. you helped me find where they were going. I have shortened my path to accommodate the problem.

from epg.

AndMetal avatar AndMetal commented on May 27, 2024

I believe this is an issue with how Storage is being used in guide.ts.

In the constructor, Storage is called with no arguments:

constructor({ channels, programs, logger, filepath, gzip }: GuideProps) {
this.channels = channels
this.programs = programs
this.logger = logger
this.storage = new Storage()
this.filepath = filepath
this.gzip = gzip || false
}

Looking at the code for @freearhey/core (src/storage.ts), if a root directory path is passed it is used, otherwise it uses the current working directory:

  constructor(rootDir?: string) {
    this._rootDir = rootDir ? path.resolve(rootDir) : process.cwd()
  }

When the save call is made:

const xmlFilepath = this.filepath
this.logger.info(` saving to "${xmlFilepath}"...`)
await this.storage.save(xmlFilepath, xmltv.toString())
if (this.gzip) {
const zip = new Zip()
const compressed = await zip.compress(xmltv.toString())
const gzFilepath = `${this.filepath}.gz`
this.logger.info(` saving to "${gzFilepath}"...`)
await this.storage.save(gzFilepath, compressed)
}

it gets mapped to _write in Storage which adds the path to the root directory:

  async _write(filepath: string, data: any = ''): Promise<void> {
    const absFilepath = path.join(this._rootDir, filepath)
    const dir = path.dirname(absFilepath)

    await this.createDir(dir)
    await fs.writeFile(absFilepath, data, { encoding: 'utf8', flag: 'w' })
  }

which is the working directory the script was called from.

I believe the fix would be to utilize Path in @freearhey/core to get the dirname of the output option and pass that to the Storage constructor. From what I can tell if it is just a filename/pattern or references a relative path it should default to the current working directory as a base, so in theory it should be mostly backwards compatible.

Edit: as a workaround you might be able to use ../../download/xml/id.xml for the output option.

Edit 2: I confirmed ../../download/xml/id.xml works to put the file into that other directory. I still think absolute paths should be allowable and handled like I mentioned above.

from epg.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.