Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

103
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda