Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

100
Views
Custom fetch to mock fetch api to read data from filesystem instead of http

In my project there is a function someFunction which use fetch api to read file from http server so its slow.

I want to repalce this someFunction by my mock_someFunction which will read file from filesystem. Reading from file system would be faster then http call.

// this use http call to fetch file, this is slow
function someFunction(fileName) {
    let url = `https://${HOST}/${fileName}`
    let e = fetch(url).then(function (response) {
        // response is instance of Response
        return response.arrayBuffer();
    });
    return e;
}

// this fetch file from file system, this would be fast
function mock_someFunction(fileName) {
    // we already have this file on file system so lets not use fetch api

    let e = localFetch(fileName).then(function (response) {
        // response should be instance of Response
        return response.arrayBuffer();
    })
    return e;
}

// implement this
function localFetch(fileName) {
    // read file
    var myBlob = new Blob();
    var init = { "status" : 200 , "statusText" : "SuperSmashingGreat!" };
    var myResponse = new Response(myBlob,init);
    // return reposnce promise
}

What should be way to create mock_someFunction function to make it replaceable by someFunction?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!